mirror of
https://github.com/GTNewHorizons/EnderIO.git
synced 2026-11-18 11:29:30 +00:00
facades painted with logs can now be rotated
This commit is contained in:
1 parent
6e25da63a3
commit
bb5ec19b4f
10 files changed
+157
-36
No files matched your search
@@ -53,6 +53,7 @@ import crazypants.enderio.conduit.packet.PacketItemConduitFilter;
|
||||
import crazypants.enderio.conduit.packet.PacketRedstoneConduitOutputStrength;
|
||||
import crazypants.enderio.conduit.packet.PacketRedstoneConduitSignalColor;
|
||||
import crazypants.enderio.conduit.redstone.IRedstoneConduit;
|
||||
import crazypants.enderio.item.IRotatableFacade;
|
||||
import crazypants.enderio.item.ItemConduitProbe;
|
||||
import crazypants.enderio.machine.painter.PainterUtil;
|
||||
import crazypants.enderio.network.PacketHandler;
|
||||
@@ -62,7 +63,7 @@ import crazypants.util.IFacade;
|
||||
import crazypants.util.Util;
|
||||
|
||||
@Optional.Interface(iface = "powercrystals.minefactoryreloaded.api.rednet.IRedNetOmniNode", modid = "MineFactoryReloaded")
|
||||
public class BlockConduitBundle extends BlockEio implements IGuiHandler, IFacade, IRedNetOmniNode {
|
||||
public class BlockConduitBundle extends BlockEio implements IGuiHandler, IFacade, IRotatableFacade, IRedNetOmniNode {
|
||||
|
||||
private static final String KEY_CONNECTOR_ICON = "enderIO:conduitConnector";
|
||||
private static final String KEY_CONNECTOR_ICON_EXTERNAL = "enderIO:conduitConnectorExternal";
|
||||
@@ -96,7 +97,7 @@ public class BlockConduitBundle extends BlockEio implements IGuiHandler, IFacade
|
||||
|
||||
private IIcon lastRemovedComponetIcon = null;
|
||||
|
||||
private Random rand = new Random();
|
||||
private final Random rand = new Random();
|
||||
|
||||
protected BlockConduitBundle() {
|
||||
super(ModObject.blockConduitBundle.unlocalisedName, TileConduitBundle.class);
|
||||
@@ -255,10 +256,7 @@ public class BlockConduitBundle extends BlockEio implements IGuiHandler, IFacade
|
||||
return false;
|
||||
}
|
||||
IConduitBundle con = (IConduitBundle) te;
|
||||
if(con.getFacadeId() != null) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return con.hasFacade();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -475,9 +473,7 @@ public class BlockConduitBundle extends BlockEio implements IGuiHandler, IFacade
|
||||
return;
|
||||
}
|
||||
IConduitBundle te = (IConduitBundle) tile;
|
||||
if(te != null) {
|
||||
te.onBlockRemoved();
|
||||
}
|
||||
te.onBlockRemoved();
|
||||
world.removeTileEntity(x, y, z);
|
||||
}
|
||||
|
||||
@@ -492,7 +488,7 @@ public class BlockConduitBundle extends BlockEio implements IGuiHandler, IFacade
|
||||
|
||||
@Override
|
||||
public boolean onBlockActivated(World world, int x, int y, int z,
|
||||
EntityPlayer player, int par6, float par7, float par8, float par9) {
|
||||
EntityPlayer player, int side, float par7, float par8, float par9) {
|
||||
|
||||
IConduitBundle bundle = (IConduitBundle) world.getTileEntity(x, y, z);
|
||||
if(bundle == null) {
|
||||
@@ -502,7 +498,7 @@ public class BlockConduitBundle extends BlockEio implements IGuiHandler, IFacade
|
||||
ItemStack stack = player.getCurrentEquippedItem();
|
||||
if(stack != null && stack.getItem() == EnderIO.itemConduitFacade && !bundle.hasFacade()) {
|
||||
//add facade
|
||||
return handleFacadeClick(world, x, y, z, player, bundle, stack);
|
||||
return handleFacadeClick(world, x, y, z, player, side, bundle, stack);
|
||||
|
||||
} else if(ConduitUtil.isConduitEquipped(player)) {
|
||||
// Add conduit
|
||||
@@ -632,18 +628,22 @@ public class BlockConduitBundle extends BlockEio implements IGuiHandler, IFacade
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean handleFacadeClick(World world, int x, int y, int z, EntityPlayer player, IConduitBundle bundle, ItemStack stack) {
|
||||
private boolean handleFacadeClick(World world, int x, int y, int z, EntityPlayer player, int side, IConduitBundle bundle, ItemStack stack) {
|
||||
// Add facade
|
||||
if(player.isSneaking()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if(PainterUtil.getSourceBlock(player.getCurrentEquippedItem()) == null) {
|
||||
Block facadeID = PainterUtil.getSourceBlock(player.getCurrentEquippedItem());
|
||||
if(facadeID == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bundle.setFacadeId(PainterUtil.getSourceBlock(player.getCurrentEquippedItem()));
|
||||
bundle.setFacadeMetadata(PainterUtil.getSourceBlockMetadata(player.getCurrentEquippedItem()));
|
||||
int facadeMeta = PainterUtil.getSourceBlockMetadata(player.getCurrentEquippedItem());
|
||||
facadeMeta = PainterUtil.adjustFacadeMetadata(facadeID, facadeMeta, side);
|
||||
|
||||
bundle.setFacadeId(facadeID);
|
||||
bundle.setFacadeMetadata(facadeMeta);
|
||||
bundle.setFacadeType(FacadeType.values()[player.getCurrentEquippedItem().getItemDamage()]);
|
||||
if(!player.capabilities.isCreativeMode) {
|
||||
stack.stackSize--;
|
||||
@@ -653,6 +653,25 @@ public class BlockConduitBundle extends BlockEio implements IGuiHandler, IFacade
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean tryRotateFacade(World world, int x, int y, int z, ForgeDirection axis) {
|
||||
IConduitBundle bundle = (IConduitBundle) world.getTileEntity(x, y, z);
|
||||
if(bundle == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int oldMeta = bundle.getFacadeMetadata();
|
||||
int newMeta = PainterUtil.rotateFacadeMetadata(bundle.getFacadeId(), oldMeta, axis);
|
||||
if(newMeta == oldMeta) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bundle.setFacadeMetadata(newMeta);
|
||||
world.markBlockForUpdate(x, y, z);
|
||||
bundle.getEntity().markDirty();
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getServerGuiElement(int id, EntityPlayer player, World world, int x, int y, int z) {
|
||||
if(id == GuiHandler.GUI_ID_EXTERNAL_CONNECTION_SELECTOR) {
|
||||
|
||||
@@ -14,7 +14,8 @@ public enum ConduitDisplayMode {
|
||||
FLUID,
|
||||
ITEM,
|
||||
GAS,
|
||||
ME;
|
||||
ME,
|
||||
NONE;
|
||||
|
||||
public static ConduitDisplayMode next(ConduitDisplayMode mode) {
|
||||
int index = mode.ordinal() + 1;
|
||||
|
||||
@@ -119,8 +119,11 @@ public class ItemConduitFacade extends Item implements IAdvancedTooltipProvider,
|
||||
|
||||
world.setBlock(placeX, placeY, placeZ, EnderIO.blockConduitBundle);
|
||||
IConduitBundle bundle = (IConduitBundle) world.getTileEntity(placeX, placeY, placeZ);
|
||||
bundle.setFacadeId(PainterUtil.getSourceBlock(itemStack));
|
||||
bundle.setFacadeMetadata(PainterUtil.getSourceBlockMetadata(itemStack));
|
||||
Block facadeID = PainterUtil.getSourceBlock(itemStack);
|
||||
int facadeMeta = PainterUtil.getSourceBlockMetadata(itemStack);
|
||||
facadeMeta = PainterUtil.adjustFacadeMetadata(facadeID, facadeMeta, side);
|
||||
bundle.setFacadeId(facadeID);
|
||||
bundle.setFacadeMetadata(facadeMeta);
|
||||
bundle.setFacadeType(FacadeType.values()[itemStack.getItemDamage()]);
|
||||
if(!player.capabilities.isCreativeMode) {
|
||||
itemStack.stackSize--;
|
||||
|
||||
@@ -11,8 +11,6 @@ import org.lwjgl.opengl.GL11;
|
||||
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import crazypants.enderio.EnderIO;
|
||||
import crazypants.enderio.conduit.ConduitDisplayMode;
|
||||
import crazypants.enderio.conduit.gas.GasUtil;
|
||||
import crazypants.enderio.gui.IconEIO;
|
||||
|
||||
public class ConduitProbeOverlayRenderer {
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
package crazypants.enderio.item;
|
||||
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
public interface IRotatableFacade {
|
||||
boolean tryRotateFacade(World world, int x, int y, int z, ForgeDirection axis);
|
||||
}
|
||||
@@ -23,6 +23,7 @@ import crazypants.enderio.EnderIOTab;
|
||||
import crazypants.enderio.ModObject;
|
||||
import crazypants.enderio.api.tool.IConduitControl;
|
||||
import crazypants.enderio.api.tool.ITool;
|
||||
import crazypants.enderio.conduit.BlockConduitBundle;
|
||||
import crazypants.enderio.conduit.ConduitDisplayMode;
|
||||
import crazypants.enderio.config.Config;
|
||||
import crazypants.enderio.gui.IAdvancedTooltipProvider;
|
||||
@@ -62,10 +63,20 @@ public class ItemYetaWrench extends Item implements ITool, IConduitControl, IAdv
|
||||
|
||||
@Override
|
||||
public boolean onItemUseFirst(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ) {
|
||||
if(world.isRemote) {
|
||||
return false;
|
||||
}
|
||||
Block block = world.getBlock(x, y, z);
|
||||
if(block instanceof IRotatableFacade && !player.isSneaking() &&
|
||||
(block != EnderIO.blockConduitBundle || ConduitDisplayMode.getDisplayMode(stack) == ConduitDisplayMode.NONE)) {
|
||||
if(((IRotatableFacade)block).tryRotateFacade(world, x, y, z, ForgeDirection.getOrientation(side))) {
|
||||
player.swingItem();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if(block != null && !player.isSneaking() && block.rotateBlock(world, x, y, z, ForgeDirection.getOrientation(side))) {
|
||||
player.swingItem();
|
||||
return !world.isRemote;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -114,7 +125,8 @@ public class ItemYetaWrench extends Item implements ITool, IConduitControl, IAdv
|
||||
|
||||
@Override
|
||||
public boolean shouldHideFacades(ItemStack stack, EntityPlayer player) {
|
||||
return true;
|
||||
ConduitDisplayMode curMode = ConduitDisplayMode.getDisplayMode(stack);
|
||||
return curMode != ConduitDisplayMode.NONE;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -9,6 +9,8 @@ import net.minecraft.item.ItemStack;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import crazypants.enderio.EnderIO;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class BlockItemPaintedGlowstone extends ItemBlock {
|
||||
|
||||
@@ -27,6 +29,24 @@ public class BlockItemPaintedGlowstone extends ItemBlock {
|
||||
return par1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean placeBlockAt(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ, int metadata) {
|
||||
if(!super.placeBlockAt(stack, player, world, x, y, z, side, hitX, hitY, hitZ, metadata)) {
|
||||
return false;
|
||||
}
|
||||
Block b = PainterUtil.getSourceBlock(stack);
|
||||
TileEntity te = world.getTileEntity(x, y, z);
|
||||
if(te instanceof TileEntityPaintedBlock) {
|
||||
TileEntityPaintedBlock tef = (TileEntityPaintedBlock) te;
|
||||
int meta = PainterUtil.getSourceBlockMetadata(stack);
|
||||
meta = PainterUtil.adjustFacadeMetadata(b, meta, side);
|
||||
tef.setSourceBlock(b);
|
||||
tef.setSourceBlockMetadata(meta);
|
||||
world.markBlockForUpdate(x, y, z);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void addInformation(ItemStack item, EntityPlayer par2EntityPlayer, List list, boolean par4) {
|
||||
|
||||
@@ -10,7 +10,6 @@ import net.minecraft.client.particle.EffectRenderer;
|
||||
import net.minecraft.client.particle.EntityDiggingFX;
|
||||
import net.minecraft.client.renderer.texture.IIconRegister;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -31,12 +30,13 @@ import crazypants.enderio.BlockEio;
|
||||
import crazypants.enderio.EnderIO;
|
||||
import crazypants.enderio.ModObject;
|
||||
import crazypants.enderio.TileEntityEio;
|
||||
import crazypants.enderio.item.IRotatableFacade;
|
||||
import crazypants.enderio.machine.MachineRecipeInput;
|
||||
import crazypants.enderio.machine.MachineRecipeRegistry;
|
||||
import crazypants.util.IFacade;
|
||||
import crazypants.util.Lang;
|
||||
|
||||
public class BlockPaintedGlowstone extends BlockEio implements ITileEntityProvider, IPaintedBlock, IFacade {
|
||||
public class BlockPaintedGlowstone extends BlockEio implements ITileEntityProvider, IPaintedBlock, IFacade, IRotatableFacade {
|
||||
|
||||
public static int renderId = -1;
|
||||
|
||||
@@ -48,7 +48,7 @@ public class BlockPaintedGlowstone extends BlockEio implements ITileEntityProvid
|
||||
|
||||
private IIcon lastRemovedComponetIcon = null;
|
||||
|
||||
private Random rand = new Random();
|
||||
private final Random rand = new Random();
|
||||
|
||||
protected BlockPaintedGlowstone() {
|
||||
super(ModObject.blockPaintedGlowstone.unlocalisedName, TileEntityPaintedBlock.class, Material.glass);
|
||||
@@ -196,16 +196,20 @@ public class BlockPaintedGlowstone extends BlockEio implements ITileEntityProvid
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase player, ItemStack stack) {
|
||||
Block b = PainterUtil.getSourceBlock(stack);
|
||||
public boolean tryRotateFacade(World world, int x, int y, int z, ForgeDirection axis) {
|
||||
TileEntity te = world.getTileEntity(x, y, z);
|
||||
if(te instanceof TileEntityPaintedBlock) {
|
||||
TileEntityPaintedBlock tef = (TileEntityPaintedBlock) te;
|
||||
tef.setSourceBlock(b);
|
||||
tef.setSourceBlockMetadata(PainterUtil.getSourceBlockMetadata(stack));
|
||||
int oldMeta = tef.getSourceBlockMetadata();
|
||||
int newMeta = PainterUtil.rotateFacadeMetadata(tef.getSourceBlock(), oldMeta, axis);
|
||||
if(oldMeta != newMeta) {
|
||||
tef.setSourceBlockMetadata(newMeta);
|
||||
world.markBlockForUpdate(x, y, z);
|
||||
tef.markDirty();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
world.markBlockForUpdate(x, y, z);
|
||||
super.onBlockPlacedBy(world, x, y, z, player, stack);
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -3,12 +3,13 @@ package crazypants.enderio.machine.painter;
|
||||
import com.google.common.base.Strings;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockRotatedPillar;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import cpw.mods.fml.common.registry.GameData;
|
||||
import crazypants.util.Lang;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
public final class PainterUtil {
|
||||
|
||||
@@ -56,10 +57,8 @@ public final class PainterUtil {
|
||||
Block sourceId = PainterUtil.getSourceBlock(item);
|
||||
int meta = PainterUtil.getSourceBlockMetadata(item);
|
||||
if(sourceId != null) {
|
||||
if(sourceId != null) {
|
||||
ItemStack is = new ItemStack(Item.getItemFromBlock(sourceId), 1, meta);
|
||||
sourceName = is.getDisplayName();
|
||||
}
|
||||
ItemStack is = new ItemStack(Item.getItemFromBlock(sourceId), 1, meta);
|
||||
sourceName = is.getDisplayName();
|
||||
}
|
||||
return Lang.localize("blockPainter.paintedWith") + " " + sourceName;
|
||||
}
|
||||
@@ -79,6 +78,7 @@ public final class PainterUtil {
|
||||
}
|
||||
String name = Block.blockRegistry.getNameForObject(source);
|
||||
if(name != null && !name.trim().isEmpty()) {
|
||||
meta = normalizeFacadeMetadata(source, meta);
|
||||
tag.setString(BlockPainter.KEY_SOURCE_BLOCK_ID, name);
|
||||
tag.setInteger(BlockPainter.KEY_SOURCE_BLOCK_META, meta);
|
||||
}
|
||||
@@ -88,4 +88,52 @@ public final class PainterUtil {
|
||||
setSourceBlock(stack, Blocks.stone, 0);
|
||||
return stack;
|
||||
}
|
||||
|
||||
public static int normalizeFacadeMetadata(Block facadeID, int facadeMeta) {
|
||||
if(facadeID instanceof BlockRotatedPillar) {
|
||||
return facadeMeta & 3;
|
||||
}
|
||||
return facadeMeta;
|
||||
}
|
||||
|
||||
public static int adjustFacadeMetadata(Block facadeID, int facadeMeta, int side) {
|
||||
if(facadeID instanceof BlockRotatedPillar) {
|
||||
int dir = facadeMeta & 0xC;
|
||||
switch (side) {
|
||||
case 0:
|
||||
case 1: dir = 0; break;
|
||||
case 4:
|
||||
case 5: dir = 4; break;
|
||||
case 2:
|
||||
case 3: dir = 8; break;
|
||||
}
|
||||
facadeMeta = (facadeMeta & 3) | dir;
|
||||
}
|
||||
return facadeMeta;
|
||||
}
|
||||
|
||||
public static int rotateFacadeMetadata(Block facadeID, int facadeMeta, ForgeDirection axis) {
|
||||
if(facadeID instanceof BlockRotatedPillar) {
|
||||
int dir = facadeMeta & 0xC;
|
||||
ForgeDirection orientation;
|
||||
switch (dir) {
|
||||
case 0: orientation = ForgeDirection.UP; break;
|
||||
case 4: orientation = ForgeDirection.EAST; break;
|
||||
case 8: orientation = ForgeDirection.SOUTH; break;
|
||||
default: return facadeMeta;
|
||||
}
|
||||
orientation = orientation.getRotation(axis);
|
||||
switch (orientation) {
|
||||
case UP:
|
||||
case DOWN: dir = 0; break;
|
||||
case WEST:
|
||||
case EAST: dir = 4; break;
|
||||
case NORTH:
|
||||
case SOUTH: dir = 8; break;
|
||||
default: return facadeMeta;
|
||||
}
|
||||
return (facadeMeta & 3) | dir;
|
||||
}
|
||||
return facadeMeta;
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,8 @@ package crazypants.enderio.machine.painter;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.network.NetworkManager;
|
||||
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
|
||||
import crazypants.enderio.TileEntityEio;
|
||||
|
||||
public class TileEntityPaintedBlock extends TileEntityEio implements IPaintableTileEntity {
|
||||
@@ -30,6 +32,12 @@ public class TileEntityPaintedBlock extends TileEntityEio implements IPaintableT
|
||||
nbtRoot.setInteger(KEY_SOURCE_BLOCK_META, sourceBlockMetadata);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt) {
|
||||
super.onDataPacket(net, pkt);
|
||||
updateBlock();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Block getSourceBlock() {
|
||||
return sourceBlock;
|
||||
|
||||
Reference in new issue
Block a user