mirror of
https://github.com/GTNewHorizons/ForgeMultipart.git
synced 2026-11-22 13:09:44 +00:00
Fixed torch part placement on fences
This commit is contained in:
1 parent
0836b3d0ee
commit
c5168ff047
3 files changed
+43
-4
No files matched your search
@@ -6,6 +6,7 @@ import codechicken.lib.vec.BlockCoord;
|
||||
import codechicken.lib.vec.Vector3;
|
||||
import codechicken.multipart.TileMultipart;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockFence;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.network.packet.Packet15Place;
|
||||
@@ -62,7 +63,7 @@ public class EventHandler
|
||||
{
|
||||
Vector3 f = new Vector3(hit.hitVec).add(-hit.blockX, -hit.blockY, -hit.blockZ);
|
||||
Block block = Block.blocksList[world.getBlockId(hit.blockX, hit.blockY, hit.blockZ)];
|
||||
if(block != null && block.onBlockActivated(world, hit.blockX, hit.blockY, hit.blockZ, player, hit.sideHit, (float)f.x, (float)f.y, (float)f.z))
|
||||
if(block != null && !ignoreActivate(block) && block.onBlockActivated(world, hit.blockX, hit.blockY, hit.blockZ, player, hit.sideHit, (float)f.x, (float)f.y, (float)f.z))
|
||||
{
|
||||
player.swingItem();
|
||||
PacketCustom.sendToServer(new Packet15Place(
|
||||
@@ -101,4 +102,14 @@ public class EventHandler
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Because vanilla is weird.
|
||||
*/
|
||||
private static boolean ignoreActivate(Block block)
|
||||
{
|
||||
if(block instanceof BlockFence)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -26,10 +26,15 @@ public abstract class McSidedMetaPart extends McMetaPart
|
||||
dropIfCantStay();
|
||||
}
|
||||
|
||||
public boolean dropIfCantStay()
|
||||
public boolean canStay()
|
||||
{
|
||||
BlockCoord pos = new BlockCoord(getTile()).offset(sideForMeta(meta));
|
||||
if(!world().isBlockSolidOnSide(pos.x, pos.y, pos.z, ForgeDirection.getOrientation(sideForMeta(meta)^1)))
|
||||
return world().isBlockSolidOnSide(pos.x, pos.y, pos.z, ForgeDirection.getOrientation(sideForMeta(meta)^1));
|
||||
}
|
||||
|
||||
public boolean dropIfCantStay()
|
||||
{
|
||||
if(!canStay())
|
||||
{
|
||||
drop();
|
||||
return true;
|
||||
|
||||
@@ -65,13 +65,36 @@ public class TorchPart extends McSidedMetaPart implements IRandomDisplayTick
|
||||
return metaSideMap[meta];
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canStay()
|
||||
{
|
||||
if(sideForMeta(meta) == 0)
|
||||
{
|
||||
Block block = Block.blocksList[world().getBlockId(x(), y()-1, z())];
|
||||
if(block != null && block.canPlaceTorchOnTop(world(), x(), y()-1, z()))
|
||||
return true;
|
||||
}
|
||||
return super.canStay();
|
||||
}
|
||||
|
||||
public static McBlockPart placement(World world, BlockCoord pos, int side)
|
||||
{
|
||||
if(side == 0)
|
||||
return null;
|
||||
pos = pos.copy().offset(side^1);
|
||||
if(!world.isBlockSolidOnSide(pos.x, pos.y, pos.z, ForgeDirection.getOrientation(side)))
|
||||
return null;
|
||||
{
|
||||
if(side == 1)
|
||||
{
|
||||
Block block = Block.blocksList[world.getBlockId(pos.x, pos.y, pos.z)];
|
||||
if(block == null || !block.canPlaceTorchOnTop(world, pos.x, pos.y, pos.z))
|
||||
return null;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return new TorchPart(sideMetaMap[side^1]);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user