Reduce copying of positions from block states

This commit is contained in:
md_5 2018-12-22 11:32:11 +11:00
parent 91cae6efbf
commit dff66dfccd
10 changed files with 25 additions and 32 deletions

View File

@ -63,7 +63,7 @@
+ } + }
+ +
+ for (CraftBlockState block : blocks) { + for (CraftBlockState block : blocks) {
+ BlockPosition blockposition2 = new BlockPosition(block.getX(), block.getY(), block.getZ()); + BlockPosition blockposition2 = block.getPosition();
+ IBlockData iblockdata = world.getType(blockposition2); + IBlockData iblockdata = world.getType(blockposition2);
+ Fluid fluid = world.getFluid(blockposition2); + Fluid fluid = world.getFluid(blockposition2);
+ Material material = iblockdata.getMaterial(); + Material material = iblockdata.getMaterial();

View File

@ -85,7 +85,7 @@
EntityHuman entityhuman = itemactioncontext.getEntity(); EntityHuman entityhuman = itemactioncontext.getEntity();
BlockPosition blockposition = itemactioncontext.getClickPosition(); BlockPosition blockposition = itemactioncontext.getClickPosition();
ShapeDetectorBlock shapedetectorblock = new ShapeDetectorBlock(itemactioncontext.getWorld(), blockposition, false); ShapeDetectorBlock shapedetectorblock = new ShapeDetectorBlock(itemactioncontext.getWorld(), blockposition, false);
@@ -106,12 +146,147 @@ @@ -106,12 +146,144 @@
if (entityhuman != null && !entityhuman.abilities.mayBuild && !this.b(itemactioncontext.getWorld().F(), shapedetectorblock)) { if (entityhuman != null && !entityhuman.abilities.mayBuild && !this.b(itemactioncontext.getWorld().F(), shapedetectorblock)) {
return EnumInteractionResult.PASS; return EnumInteractionResult.PASS;
} else { } else {
@ -178,12 +178,9 @@
+ } + }
+ +
+ for (BlockState blockstate : blocks) { + for (BlockState blockstate : blocks) {
+ int x = blockstate.getX();
+ int y = blockstate.getY();
+ int z = blockstate.getZ();
+ int updateFlag = ((CraftBlockState) blockstate).getFlag(); + int updateFlag = ((CraftBlockState) blockstate).getFlag();
+ IBlockData oldBlock = ((CraftBlockState) blockstate).getHandle(); + IBlockData oldBlock = ((CraftBlockState) blockstate).getHandle();
+ BlockPosition newblockposition = new BlockPosition(x, y, z); + BlockPosition newblockposition = ((CraftBlockState) blockstate).getPosition();
+ IBlockData block = world.getType(newblockposition); + IBlockData block = world.getType(newblockposition);
+ +
+ if (!(block.getBlock() instanceof BlockTileEntity)) { // Containers get placed automatically + if (!(block.getBlock() instanceof BlockTileEntity)) { // Containers get placed automatically
@ -234,7 +231,7 @@
return enuminteractionresult; return enuminteractionresult;
} }
@@ -135,7 +310,7 @@ @@ -135,7 +307,7 @@
nbttagcompound.setString("id", minecraftkey == null ? "minecraft:air" : minecraftkey.toString()); nbttagcompound.setString("id", minecraftkey == null ? "minecraft:air" : minecraftkey.toString());
nbttagcompound.setByte("Count", (byte) this.count); nbttagcompound.setByte("Count", (byte) this.count);
if (this.tag != null) { if (this.tag != null) {
@ -243,7 +240,7 @@
} }
return nbttagcompound; return nbttagcompound;
@@ -213,6 +388,11 @@ @@ -213,6 +385,11 @@
if (this.isDamaged(i, entityliving.getRandom(), entityliving instanceof EntityPlayer ? (EntityPlayer) entityliving : null)) { if (this.isDamaged(i, entityliving.getRandom(), entityliving instanceof EntityPlayer ? (EntityPlayer) entityliving : null)) {
entityliving.c(this); entityliving.c(this);
Item item = this.getItem(); Item item = this.getItem();
@ -255,7 +252,7 @@
this.subtract(1); this.subtract(1);
if (entityliving instanceof EntityHuman) { if (entityliving instanceof EntityHuman) {
@@ -336,6 +516,17 @@ @@ -336,6 +513,17 @@
return this.tag; return this.tag;
} }
@ -273,7 +270,7 @@
public NBTTagCompound getOrCreateTag() { public NBTTagCompound getOrCreateTag() {
if (this.tag == null) { if (this.tag == null) {
this.setTag(new NBTTagCompound()); this.setTag(new NBTTagCompound());
@@ -480,6 +671,14 @@ @@ -480,6 +668,14 @@
} }
public void setRepairCost(int i) { public void setRepairCost(int i) {
@ -288,7 +285,7 @@
this.getOrCreateTag().setInt("RepairCost", i); this.getOrCreateTag().setInt("RepairCost", i);
} }
@@ -522,6 +721,13 @@ @@ -522,6 +718,13 @@
nbttaglist.add((NBTBase) nbttagcompound); nbttaglist.add((NBTBase) nbttagcompound);
} }

View File

@ -125,7 +125,7 @@
+ Iterator<CraftBlockState> it = capturedBlockStates.iterator(); + Iterator<CraftBlockState> it = capturedBlockStates.iterator();
+ while (it.hasNext()) { + while (it.hasNext()) {
+ CraftBlockState previous = it.next(); + CraftBlockState previous = it.next();
+ if (previous.getX() == blockposition.getX() && previous.getY() == blockposition.getY() && previous.getZ() == blockposition.getZ()) { + if (previous.getPosition().equals(blockposition)) {
+ blockstate = previous; + blockstate = previous;
+ it.remove(); + it.remove();
+ break; + break;
@ -287,7 +287,7 @@
+ Iterator<CraftBlockState> it = capturedBlockStates.iterator(); + Iterator<CraftBlockState> it = capturedBlockStates.iterator();
+ while (it.hasNext()) { + while (it.hasNext()) {
+ CraftBlockState previous = it.next(); + CraftBlockState previous = it.next();
+ if (previous.getX() == blockposition.getX() && previous.getY() == blockposition.getY() && previous.getZ() == blockposition.getZ()) { + if (previous.getPosition().equals(blockposition)) {
+ return previous.getHandle(); + return previous.getHandle();
+ } + }
+ } + }

View File

@ -416,13 +416,10 @@ public class CraftWorld implements World {
world.captureTreeGeneration = false; world.captureTreeGeneration = false;
if (grownTree) { // Copy block data to delegate if (grownTree) { // Copy block data to delegate
for (BlockState blockstate : world.capturedBlockStates) { for (BlockState blockstate : world.capturedBlockStates) {
int x = blockstate.getX(); BlockPosition position = ((CraftBlockState) blockstate).getPosition();
int y = blockstate.getY();
int z = blockstate.getZ();
BlockPosition position = new BlockPosition(x, y, z);
net.minecraft.server.IBlockData oldBlock = world.getType(position); net.minecraft.server.IBlockData oldBlock = world.getType(position);
int flag = ((CraftBlockState) blockstate).getFlag(); int flag = ((CraftBlockState) blockstate).getFlag();
delegate.setBlockData(x, y, z, blockstate.getBlockData()); delegate.setBlockData(blockstate.getX(), blockstate.getY(), blockstate.getZ(), blockstate.getBlockData());
net.minecraft.server.IBlockData newBlock = world.getType(position); net.minecraft.server.IBlockData newBlock = world.getType(position);
world.notifyAndUpdatePhysics(position, null, oldBlock, newBlock, newBlock, flag); world.notifyAndUpdatePhysics(position, null, oldBlock, newBlock, newBlock, flag);
} }
@ -434,10 +431,6 @@ public class CraftWorld implements World {
} }
} }
public TileEntity getTileEntityAt(final int x, final int y, final int z) {
return world.getTileEntity(new BlockPosition(x, y, z));
}
public String getName() { public String getName() {
return world.worldData.getName(); return world.worldData.getName();
} }

View File

@ -21,7 +21,7 @@ public class CraftBlockEntityState<T extends TileEntity> extends CraftBlockState
// get tile entity from block: // get tile entity from block:
CraftWorld world = (CraftWorld) this.getWorld(); CraftWorld world = (CraftWorld) this.getWorld();
this.tileEntity = tileEntityClass.cast(world.getTileEntityAt(this.getX(), this.getY(), this.getZ())); this.tileEntity = tileEntityClass.cast(world.getHandle().getTileEntity(this.getPosition()));
// copy tile entity data: // copy tile entity data:
this.snapshot = this.createSnapshot(tileEntity, world.getHandle()); this.snapshot = this.createSnapshot(tileEntity, world.getHandle());
@ -74,7 +74,7 @@ public class CraftBlockEntityState<T extends TileEntity> extends CraftBlockState
protected TileEntity getTileEntityFromWorld() { protected TileEntity getTileEntityFromWorld() {
requirePlaced(); requirePlaced();
return ((CraftWorld) this.getWorld()).getTileEntityAt(this.getX(), this.getY(), this.getZ()); return ((CraftWorld) this.getWorld()).getHandle().getTileEntity(this.getPosition());
} }
// gets the NBT data of the TileEntity represented by this block state // gets the NBT data of the TileEntity represented by this block state

View File

@ -25,7 +25,7 @@ import net.minecraft.server.IBlockData;
public class CraftBlockState implements BlockState { public class CraftBlockState implements BlockState {
private final CraftWorld world; private final CraftWorld world;
private final CraftChunk chunk; private final CraftChunk chunk;
protected final BlockPosition position; private final BlockPosition position;
protected IBlockData data; protected IBlockData data;
protected int flag; protected int flag;
@ -83,6 +83,10 @@ public class CraftBlockState implements BlockState {
this.data = data; this.data = data;
} }
public BlockPosition getPosition() {
return this.position;
}
public IBlockData getHandle() { public IBlockData getHandle() {
return this.data; return this.data;
} }

View File

@ -1,7 +1,6 @@
package org.bukkit.craftbukkit.block; package org.bukkit.craftbukkit.block;
import net.minecraft.server.BlockChest; import net.minecraft.server.BlockChest;
import net.minecraft.server.BlockPosition;
import net.minecraft.server.Blocks; import net.minecraft.server.Blocks;
import net.minecraft.server.ITileInventory; import net.minecraft.server.ITileInventory;
import net.minecraft.server.InventoryLargeChest; import net.minecraft.server.InventoryLargeChest;
@ -50,7 +49,7 @@ public class CraftChest extends CraftLootable<TileEntityChest> implements Chest
CraftWorld world = (CraftWorld) this.getWorld(); CraftWorld world = (CraftWorld) this.getWorld();
BlockChest blockChest = (BlockChest) (this.getType() == Material.CHEST ? Blocks.CHEST : Blocks.TRAPPED_CHEST); BlockChest blockChest = (BlockChest) (this.getType() == Material.CHEST ? Blocks.CHEST : Blocks.TRAPPED_CHEST);
ITileInventory nms = blockChest.getInventory(data, world.getHandle(), position, true); ITileInventory nms = blockChest.getInventory(data, world.getHandle(), this.getPosition(), true);
if (nms instanceof InventoryLargeChest) { if (nms instanceof InventoryLargeChest) {
inventory = new CraftInventoryDoubleChest((InventoryLargeChest) nms); inventory = new CraftInventoryDoubleChest((InventoryLargeChest) nms);

View File

@ -57,7 +57,7 @@ public class CraftDispenser extends CraftLootable<TileEntityDispenser> implement
CraftWorld world = (CraftWorld) this.getWorld(); CraftWorld world = (CraftWorld) this.getWorld();
BlockDispenser dispense = (BlockDispenser) Blocks.DISPENSER; BlockDispenser dispense = (BlockDispenser) Blocks.DISPENSER;
dispense.dispense(world.getHandle(), new BlockPosition(getX(), getY(), getZ())); dispense.dispense(world.getHandle(), this.getPosition());
return true; return true;
} else { } else {
return false; return false;

View File

@ -44,7 +44,7 @@ public class CraftDropper extends CraftLootable<TileEntityDropper> implements Dr
CraftWorld world = (CraftWorld) this.getWorld(); CraftWorld world = (CraftWorld) this.getWorld();
BlockDropper drop = (BlockDropper) Blocks.DROPPER; BlockDropper drop = (BlockDropper) Blocks.DROPPER;
drop.dispense(world.getHandle(), new BlockPosition(getX(), getY(), getZ())); drop.dispense(world.getHandle(), this.getPosition());
} }
} }
} }

View File

@ -31,9 +31,9 @@ public class CraftJukebox extends CraftBlockEntityState<TileEntityJukeBox> imple
CraftWorld world = (CraftWorld) this.getWorld(); CraftWorld world = (CraftWorld) this.getWorld();
Material record = this.getPlaying(); Material record = this.getPlaying();
if (record == Material.AIR) { if (record == Material.AIR) {
world.getHandle().setTypeAndData(position, Blocks.JUKEBOX.getBlockData().set(BlockJukeBox.HAS_RECORD, false), 3); world.getHandle().setTypeAndData(this.getPosition(), Blocks.JUKEBOX.getBlockData().set(BlockJukeBox.HAS_RECORD, false), 3);
} else { } else {
world.getHandle().setTypeAndData(position, Blocks.JUKEBOX.getBlockData().set(BlockJukeBox.HAS_RECORD, true), 3); world.getHandle().setTypeAndData(this.getPosition(), Blocks.JUKEBOX.getBlockData().set(BlockJukeBox.HAS_RECORD, true), 3);
} }
world.playEffect(this.getLocation(), Effect.RECORD_PLAY, record); world.playEffect(this.getLocation(), Effect.RECORD_PLAY, record);
} }
@ -86,7 +86,7 @@ public class CraftJukebox extends CraftBlockEntityState<TileEntityJukeBox> imple
TileEntityJukeBox jukebox = (TileEntityJukeBox) tileEntity; TileEntityJukeBox jukebox = (TileEntityJukeBox) tileEntity;
boolean result = !jukebox.getRecord().isEmpty(); boolean result = !jukebox.getRecord().isEmpty();
CraftWorld world = (CraftWorld) this.getWorld(); CraftWorld world = (CraftWorld) this.getWorld();
((BlockJukeBox) Blocks.JUKEBOX).dropRecord(world.getHandle(), position); ((BlockJukeBox) Blocks.JUKEBOX).dropRecord(world.getHandle(), getPosition());
return result; return result;
} }
} }