mirror of
https://github.com/GTNewHorizons/ThaumicTinkerer.git
synced 2026-10-25 20:32:29 +00:00
Fix certain block interactions + redstone mode (#72)
This commit is contained in:
1 parent
2127d30d16
commit
58676ab46d
2 files changed
+39
-23
No files matched your search
@@ -147,9 +147,10 @@ public class BlockAnimationTablet extends BlockModContainer {
|
|||||||
boolean on = (meta & 8) != 0;
|
boolean on = (meta & 8) != 0;
|
||||||
|
|
||||||
if (power && !on) {
|
if (power && !on) {
|
||||||
par1World.scheduleBlockUpdate(par2, par3, par4, this, tickRate(par1World));
|
|
||||||
par1World.setBlockMetadataWithNotify(par2, par3, par4, meta | 8, 4);
|
par1World.setBlockMetadataWithNotify(par2, par3, par4, meta | 8, 4);
|
||||||
} else if (!power && on) par1World.setBlockMetadataWithNotify(par2, par3, par4, meta & 7, 4);
|
} else if (!power && on) {
|
||||||
|
par1World.setBlockMetadataWithNotify(par2, par3, par4, meta & 7, 4);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -157,16 +158,6 @@ public class BlockAnimationTablet extends BlockModContainer {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void updateTick(World par1World, int par2, int par3, int par4, Random par5Random) {
|
|
||||||
TileEntity tile = par1World.getTileEntity(par2, par3, par4);
|
|
||||||
if (tile instanceof TileAnimationTablet tablet) {
|
|
||||||
if (tablet.redstone && tablet.isIdle()) {
|
|
||||||
tablet.initiateSwing();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onBlockActivated(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer,
|
public boolean onBlockActivated(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer,
|
||||||
int par6, float par7, float par8, float par9) {
|
int par6, float par7, float par8, float par9) {
|
||||||
|
|||||||
@@ -16,10 +16,14 @@ import java.util.List;
|
|||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.entity.Entity;
|
import net.minecraft.entity.Entity;
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
|
import net.minecraft.init.Blocks;
|
||||||
import net.minecraft.inventory.IInventory;
|
import net.minecraft.inventory.IInventory;
|
||||||
import net.minecraft.item.Item;
|
import net.minecraft.item.Item;
|
||||||
import net.minecraft.item.ItemBlock;
|
import net.minecraft.item.ItemBlock;
|
||||||
|
import net.minecraft.item.ItemHoe;
|
||||||
|
import net.minecraft.item.ItemRedstone;
|
||||||
import net.minecraft.item.ItemReed;
|
import net.minecraft.item.ItemReed;
|
||||||
|
import net.minecraft.item.ItemSeeds;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraft.nbt.NBTTagList;
|
import net.minecraft.nbt.NBTTagList;
|
||||||
@@ -157,10 +161,17 @@ public class TileAnimationTablet extends TileEntity implements IInventory, IMova
|
|||||||
worldManager.tryHarvestBlock(hit.blockX, hit.blockY, hit.blockZ);
|
worldManager.tryHarvestBlock(hit.blockX, hit.blockY, hit.blockZ);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (isIdle() && hit != null) {
|
||||||
if (isIdle() && hit != null && (!redstone || isBreaking)) {
|
if (redstone && !isBreaking) {
|
||||||
|
boolean power = worldObj.isBlockIndirectlyGettingPowered(xCoord, yCoord, zCoord)
|
||||||
|
|| worldObj.isBlockIndirectlyGettingPowered(xCoord, yCoord + 1, zCoord);
|
||||||
|
if (!power) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Block block = worldObj.getBlock(hit.blockX, hit.blockY, hit.blockZ);
|
||||||
if (hit.typeOfHit == MovingObjectPosition.MovingObjectType.MISS
|
if (hit.typeOfHit == MovingObjectPosition.MovingObjectType.MISS
|
||||||
&& (leftClick || !canPlaceItem(stack))) {
|
&& (leftClick || !canUseItem(stack, block))) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
initiateSwing();
|
initiateSwing();
|
||||||
@@ -183,9 +194,15 @@ public class TileAnimationTablet extends TileEntity implements IInventory, IMova
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean canPlaceItem(ItemStack stack) {
|
private boolean canUseItem(ItemStack stack, Block block) {
|
||||||
final Item item = stack.getItem();
|
final Item item = stack.getItem();
|
||||||
return item instanceof ItemBlock || item instanceof ItemReed;
|
if (item instanceof ItemBlock || item instanceof ItemReed || item instanceof ItemSeeds) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (item instanceof ItemRedstone) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return item instanceof ItemHoe && (block == Blocks.dirt || block == Blocks.grass);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -327,9 +344,8 @@ public class TileAnimationTablet extends TileEntity implements IInventory, IMova
|
|||||||
position.yCoord = yCoord + 0.5f;
|
position.yCoord = yCoord + 0.5f;
|
||||||
position.zCoord = zCoord + 0.5f;
|
position.zCoord = zCoord + 0.5f;
|
||||||
if (!worldObj.isAirBlock(x, y, z)) {
|
if (!worldObj.isAirBlock(x, y, z)) {
|
||||||
block.setBlockBoundsBasedOnState(worldObj, x, y, z);
|
AxisAlignedBB aabb = getBlockBoundingBox(block, x, y, z);
|
||||||
AxisAlignedBB aabb = block.getCollisionBoundingBoxFromPool(worldObj, x, y, z);
|
if (block.canCollideCheck(worldObj.getBlockMetadata(x, y, z), false)) {
|
||||||
if (aabb != null) {
|
|
||||||
hit = block.collisionRayTrace(worldObj, x, y, z, position, getMiddleOfAABB(aabb));
|
hit = block.collisionRayTrace(worldObj, x, y, z, position, getMiddleOfAABB(aabb));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -375,9 +391,8 @@ public class TileAnimationTablet extends TileEntity implements IInventory, IMova
|
|||||||
y--;
|
y--;
|
||||||
if (!worldObj.isAirBlock(x, y, z)) {
|
if (!worldObj.isAirBlock(x, y, z)) {
|
||||||
block = worldObj.getBlock(x, y, z);
|
block = worldObj.getBlock(x, y, z);
|
||||||
block.setBlockBoundsBasedOnState(worldObj, x, y, z);
|
if (block.canCollideCheck(worldObj.getBlockMetadata(x, y, z), false)) {
|
||||||
AxisAlignedBB aabb = block.getCollisionBoundingBoxFromPool(worldObj, x, y, z);
|
AxisAlignedBB aabb = getBlockBoundingBox(block, x, y, z);
|
||||||
if (aabb != null) {
|
|
||||||
Vec3 vec = getMiddleOfAABB(aabb);
|
Vec3 vec = getMiddleOfAABB(aabb);
|
||||||
vec.yCoord = (aabb.maxY - y);
|
vec.yCoord = (aabb.maxY - y);
|
||||||
hit = new MovingObjectPosition(x, y, z, ForgeDirection.UP.ordinal(), vec, false);
|
hit = new MovingObjectPosition(x, y, z, ForgeDirection.UP.ordinal(), vec, false);
|
||||||
@@ -388,6 +403,16 @@ public class TileAnimationTablet extends TileEntity implements IInventory, IMova
|
|||||||
return hit;
|
return hit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private AxisAlignedBB getBlockBoundingBox(Block block, int x, int y, int z) {
|
||||||
|
return AxisAlignedBB.getBoundingBox(
|
||||||
|
x + block.getBlockBoundsMinX(),
|
||||||
|
y + block.getBlockBoundsMinY(),
|
||||||
|
z + block.getBlockBoundsMinZ(),
|
||||||
|
x + block.getBlockBoundsMaxX(),
|
||||||
|
y + block.getBlockBoundsMaxY(),
|
||||||
|
z + block.getBlockBoundsMaxZ());
|
||||||
|
}
|
||||||
|
|
||||||
private Vec3 getMiddleOfAABB(AxisAlignedBB aabb) {
|
private Vec3 getMiddleOfAABB(AxisAlignedBB aabb) {
|
||||||
tempVec.xCoord = (aabb.minX + aabb.maxX) / 2f;
|
tempVec.xCoord = (aabb.minX + aabb.maxX) / 2f;
|
||||||
tempVec.yCoord = (aabb.minY + aabb.maxY) / 2f;
|
tempVec.yCoord = (aabb.minY + aabb.maxY) / 2f;
|
||||||
|
|||||||
Reference in new issue
Block a user