Several mimic fixes, with actually cleaned up commit history. (#1379)
* Reimplemented a lot of mimic logic and did a first run of changing how mimics store their states. * Finished removing all metadata calls for blocks replaced by mimics. * Update EntityMimic.java * Update ItemBlockMimic.java * Update TileMimic.java * How did I even replace a semicolon with a slash. * Changed all tabs to 4 spaces. Changed Serializer to StateUtil * Fixed spacing again, hopefully for the last time
This commit is contained in:
parent
7954d04421
commit
ebfd8ce9a3
6 changed files with 238 additions and 52 deletions
|
@ -6,10 +6,12 @@ import WayofTime.bloodmagic.core.RegistrarBloodMagicItems;
|
|||
import WayofTime.bloodmagic.entity.mob.EntityMimic;
|
||||
import WayofTime.bloodmagic.util.ChatUtil;
|
||||
import WayofTime.bloodmagic.util.Utils;
|
||||
import WayofTime.bloodmagic.util.StateUtil;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.projectile.EntityPotion;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.inventory.InventoryHelper;
|
||||
|
@ -39,8 +41,8 @@ public class TileMimic extends TileInventory implements ITickable {
|
|||
public boolean dropItemsOnBreak = true;
|
||||
public NBTTagCompound tileTag = new NBTTagCompound();
|
||||
public TileEntity mimicedTile = null;
|
||||
public int metaOfReplacedBlock = 0;
|
||||
|
||||
IBlockState stateOfReplacedBlock = Blocks.AIR.getDefaultState();
|
||||
|
||||
public int playerCheckRadius = 5;
|
||||
public int potionSpawnRadius = 5;
|
||||
public int potionSpawnInterval = 40;
|
||||
|
@ -134,6 +136,13 @@ public class TileMimic extends TileInventory implements ITickable {
|
|||
return false;
|
||||
|
||||
Utils.insertItemToTile(this, player, 0);
|
||||
ItemStack stack = getStackInSlot(0);
|
||||
if(stateOfReplacedBlock == Blocks.AIR.getDefaultState()) {
|
||||
if (!stack.isEmpty() && stack.getItem() instanceof ItemBlock) {
|
||||
Block block = ((ItemBlock) stack.getItem()).getBlock();
|
||||
stateOfReplacedBlock = block.getDefaultState();
|
||||
}
|
||||
}
|
||||
this.refreshTileEntity();
|
||||
|
||||
if (player.capabilities.isCreativeMode) {
|
||||
|
@ -220,7 +229,7 @@ public class TileMimic extends TileInventory implements ITickable {
|
|||
EntityMimic mimicEntity = new EntityMimic(getWorld());
|
||||
mimicEntity.setPosition(pos.getX() + 0.5, pos.getY(), pos.getZ() + 0.5);
|
||||
|
||||
mimicEntity.initializeMimic(getStackInSlot(0), tileTag, dropItemsOnBreak, metaOfReplacedBlock, playerCheckRadius, pos);
|
||||
mimicEntity.initializeMimic(getStackInSlot(0), tileTag, dropItemsOnBreak, stateOfReplacedBlock, playerCheckRadius, pos);
|
||||
tileTag = null;
|
||||
mimicedTile = null;
|
||||
this.setInventorySlotContents(0, ItemStack.EMPTY);
|
||||
|
@ -239,7 +248,7 @@ public class TileMimic extends TileInventory implements ITickable {
|
|||
if (mimicedTile != null) {
|
||||
dropMimicedTileInventory();
|
||||
}
|
||||
mimicedTile = getTileFromStackWithTag(getWorld(), pos, getStackInSlot(0), tileTag, metaOfReplacedBlock);
|
||||
mimicedTile = getTileFromStackWithTag(getWorld(), pos, getStackInSlot(0), tileTag, stateOfReplacedBlock);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -248,8 +257,8 @@ public class TileMimic extends TileInventory implements ITickable {
|
|||
|
||||
dropItemsOnBreak = tag.getBoolean("dropItemsOnBreak");
|
||||
tileTag = tag.getCompoundTag("tileTag");
|
||||
metaOfReplacedBlock = tag.getInteger("metaOfReplacedBlock");
|
||||
mimicedTile = getTileFromStackWithTag(getWorld(), pos, getStackInSlot(0), tileTag, metaOfReplacedBlock);
|
||||
stateOfReplacedBlock = StateUtil.parseState(tag.getString("stateOfReplacedBlock"));
|
||||
mimicedTile = getTileFromStackWithTag(getWorld(), pos, getStackInSlot(0), tileTag, stateOfReplacedBlock);
|
||||
playerCheckRadius = tag.getInteger("playerCheckRadius");
|
||||
potionSpawnRadius = tag.getInteger("potionSpawnRadius");
|
||||
potionSpawnInterval = Math.max(1, tag.getInteger("potionSpawnInterval"));
|
||||
|
@ -261,10 +270,10 @@ public class TileMimic extends TileInventory implements ITickable {
|
|||
|
||||
tag.setBoolean("dropItemsOnBreak", dropItemsOnBreak);
|
||||
tag.setTag("tileTag", tileTag);
|
||||
tag.setInteger("metaOfReplacedBlock", metaOfReplacedBlock);
|
||||
tag.setInteger("playerCheckRadius", playerCheckRadius);
|
||||
tag.setInteger("potionSpawnRadius", potionSpawnRadius);
|
||||
tag.setInteger("potionSpawnInterval", potionSpawnInterval);
|
||||
tag.setString("stateOfReplacedBlock",stateOfReplacedBlock.toString());
|
||||
|
||||
return tag;
|
||||
}
|
||||
|
@ -284,6 +293,14 @@ public class TileMimic extends TileInventory implements ITickable {
|
|||
}
|
||||
}
|
||||
|
||||
public IBlockState getReplacedState() {
|
||||
return stateOfReplacedBlock;
|
||||
}
|
||||
|
||||
public void setReplacedState(IBlockState state) {
|
||||
stateOfReplacedBlock = state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot(int slot, ItemStack itemstack) {
|
||||
return slot == 0 && dropItemsOnBreak;
|
||||
|
@ -293,13 +310,13 @@ public class TileMimic extends TileInventory implements ITickable {
|
|||
World world = mimic.getWorld();
|
||||
BlockPos pos = mimic.getPos();
|
||||
|
||||
replaceMimicWithBlockActual(world, pos, mimic.getStackInSlot(0), mimic.tileTag, mimic.metaOfReplacedBlock);
|
||||
replaceMimicWithBlockActual(world, pos, mimic.getStackInSlot(0), mimic.tileTag, mimic.stateOfReplacedBlock);
|
||||
}
|
||||
|
||||
public static boolean replaceMimicWithBlockActual(World world, BlockPos pos, ItemStack stack, NBTTagCompound tileTag, int replacedMeta) {
|
||||
|
||||
public static boolean replaceMimicWithBlockActual(World world, BlockPos pos, ItemStack stack, NBTTagCompound tileTag, IBlockState replacementState) {
|
||||
if (!stack.isEmpty() && stack.getItem() instanceof ItemBlock) {
|
||||
Block block = ((ItemBlock) stack.getItem()).getBlock();
|
||||
IBlockState state = block.getStateFromMeta(replacedMeta);
|
||||
IBlockState state = replacementState;
|
||||
if (world.setBlockState(pos, state, 3)) {
|
||||
TileEntity tile = world.getTileEntity(pos);
|
||||
if (tile != null) {
|
||||
|
@ -317,10 +334,10 @@ public class TileMimic extends TileInventory implements ITickable {
|
|||
}
|
||||
|
||||
@Nullable
|
||||
public static TileEntity getTileFromStackWithTag(World world, BlockPos pos, ItemStack stack, @Nullable NBTTagCompound tag, int replacementMeta) {
|
||||
public static TileEntity getTileFromStackWithTag(World world, BlockPos pos, ItemStack stack, @Nullable NBTTagCompound tag, IBlockState replacementState) {
|
||||
if (!stack.isEmpty() && stack.getItem() instanceof ItemBlock) {
|
||||
Block block = ((ItemBlock) stack.getItem()).getBlock();
|
||||
IBlockState state = block.getStateFromMeta(stack.getItemDamage());
|
||||
IBlockState state = replacementState;
|
||||
if (block.hasTileEntity(state)) {
|
||||
TileEntity tile = block.createTileEntity(world, state);
|
||||
|
||||
|
@ -338,7 +355,7 @@ public class TileMimic extends TileInventory implements ITickable {
|
|||
tile.setWorld(world);
|
||||
|
||||
try {
|
||||
_blockMetadata.setInt(tile, replacementMeta);
|
||||
_blockMetadata.setInt(tile, block.getMetaFromState(replacementState));
|
||||
} catch (IllegalArgumentException | IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
@ -349,4 +366,4 @@ public class TileMimic extends TileInventory implements ITickable {
|
|||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue