Control panels now drop properly and can be placed
added a basic GUI to panel RS connectors to allow changing the ID
This commit is contained in:
parent
3d4c2ef1f4
commit
838e9c2af4
|
@ -18,12 +18,24 @@
|
|||
package malte0811.industrialWires;
|
||||
|
||||
import malte0811.industrialWires.blocks.TileEntityJacobsLadder;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.fml.common.network.IGuiHandler;
|
||||
|
||||
public class CommonProxy {
|
||||
public class CommonProxy implements IGuiHandler {
|
||||
public void preInit() {}
|
||||
public void postInit() {}
|
||||
public World getClientWorld() {return null;}
|
||||
public void playJacobsLadderSound(TileEntityJacobsLadder te, int phase, Vec3d soundPos) {}
|
||||
|
||||
@Override
|
||||
public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
|
||||
return null;//TODO implement
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,6 +37,7 @@ import malte0811.industrialWires.blocks.converter.TileEntityMechIEtoIC;
|
|||
import malte0811.industrialWires.blocks.wire.*;
|
||||
import malte0811.industrialWires.crafting.RecipeCoilLength;
|
||||
import malte0811.industrialWires.items.ItemIC2Coil;
|
||||
import malte0811.industrialWires.network.MessageGUIInteract;
|
||||
import malte0811.industrialWires.network.MessagePanelInteract;
|
||||
import malte0811.industrialWires.network.MessageTileSyncIW;
|
||||
import malte0811.industrialWires.wires.IC2Wiretype;
|
||||
|
@ -71,6 +72,8 @@ public class IndustrialWires {
|
|||
public static BlockPanel panel;
|
||||
public static ItemIC2Coil coil;
|
||||
public static final SimpleNetworkWrapper packetHandler = NetworkRegistry.INSTANCE.newSimpleChannel(MODID);
|
||||
@Mod.Instance(MODID)
|
||||
public static IndustrialWires instance = new IndustrialWires();
|
||||
public static CreativeTabs creativeTab = new CreativeTabs(MODID) {
|
||||
|
||||
@Override
|
||||
|
@ -164,6 +167,9 @@ public class IndustrialWires {
|
|||
|
||||
packetHandler.registerMessage(MessageTileSyncIW.HandlerClient.class, MessageTileSyncIW.class, 0, Side.CLIENT);
|
||||
packetHandler.registerMessage(MessagePanelInteract.HandlerServer.class, MessagePanelInteract.class, 1, Side.SERVER);
|
||||
packetHandler.registerMessage(MessageGUIInteract.HandlerServer.class, MessageGUIInteract.class, 2, Side.SERVER);
|
||||
|
||||
NetworkRegistry.INSTANCE.registerGuiHandler(instance, proxy);
|
||||
}
|
||||
@EventHandler
|
||||
public void postInit(FMLPostInitializationEvent e) {
|
||||
|
|
|
@ -205,5 +205,17 @@ public abstract class BlockIWBase extends Block {
|
|||
return def;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void harvestBlock(World worldIn, EntityPlayer player, BlockPos pos, IBlockState state, @Nullable TileEntity te, @Nullable ItemStack stack) {
|
||||
if (te instanceof IEBlockInterfaces.ITileDrop) {
|
||||
ItemStack drop = ((IEBlockInterfaces.ITileDrop) te).getTileDrop(player, state);
|
||||
if (drop!=null) {
|
||||
spawnAsEntity(worldIn, pos, drop);
|
||||
return;
|
||||
}
|
||||
}
|
||||
super.harvestBlock(worldIn, player, pos, state, te, stack);
|
||||
}
|
||||
|
||||
protected abstract IProperty[] getProperties();
|
||||
}
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
package malte0811.industrialWires.blocks;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
public interface INetGUI {
|
||||
void onChange(NBTTagCompound nbt, EntityPlayer p);
|
||||
}
|
|
@ -65,6 +65,9 @@ public class ItemBlockIW extends ItemBlock {
|
|||
EnumFacing dir = ((IEBlockInterfaces.IDirectionalTile) te).getFacingForPlacement(player, pos, side, hitX, hitY, hitZ);
|
||||
((IEBlockInterfaces.IDirectionalTile) te).setFacing(dir);
|
||||
}
|
||||
if (te instanceof IEBlockInterfaces.ITileDrop) {
|
||||
((IEBlockInterfaces.ITileDrop) te).readOnPlacement(player, stack);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
package malte0811.industrialWires.blocks.controlpanel;
|
||||
|
||||
import blusunrize.immersiveengineering.api.IEProperties;
|
||||
import malte0811.industrialWires.IndustrialWires;
|
||||
import malte0811.industrialWires.blocks.BlockIWBase;
|
||||
import malte0811.industrialWires.blocks.IMetaEnum;
|
||||
import net.minecraft.block.material.Material;
|
||||
|
@ -27,10 +28,13 @@ import net.minecraft.block.properties.PropertyEnum;
|
|||
import net.minecraft.block.state.BlockStateContainer;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.BlockRenderLayer;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
|
@ -153,4 +157,19 @@ public class BlockPanel extends BlockIWBase implements IMetaEnum {
|
|||
public boolean isVisuallyOpaque() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ) {
|
||||
if (!super.onBlockActivated(world, pos, state, player, hand, heldItem, side, hitX, hitY, hitZ)) {
|
||||
TileEntity te = world.getTileEntity(pos);
|
||||
if (te instanceof TileEntityRSPanelConn){
|
||||
if (world.isRemote) {
|
||||
player.openGui(IndustrialWires.instance, 0, te.getWorld(), te.getPos().getX(), te.getPos().getY(), te.getPos().getZ());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,11 +30,13 @@ public class IndicatorLight extends PanelComponent {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void writeCustomNBT(NBTTagCompound nbt) {
|
||||
protected void writeCustomNBT(NBTTagCompound nbt, boolean toItem) {
|
||||
nbt.setInteger("rsId", rsInputId);
|
||||
nbt.setInteger("rsChannel", rsInputChannel);
|
||||
nbt.setInteger("color", colorA);
|
||||
nbt.setInteger("rsInput", rsInput);
|
||||
if (!toItem) {
|
||||
nbt.setInteger("rsInput", rsInput);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -27,7 +27,7 @@ public class Label extends PanelComponent {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void writeCustomNBT(NBTTagCompound nbt) {
|
||||
protected void writeCustomNBT(NBTTagCompound nbt, boolean toItem) {
|
||||
nbt.setString("text", text);
|
||||
nbt.setInteger("color", color);
|
||||
}
|
||||
|
|
|
@ -54,10 +54,12 @@ public class LightedButton extends PanelComponent {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void writeCustomNBT(NBTTagCompound nbt) {
|
||||
protected void writeCustomNBT(NBTTagCompound nbt, boolean toItem) {
|
||||
nbt.setInteger("color", color);
|
||||
nbt.setInteger("timeout", ticksTillOff);
|
||||
nbt.setBoolean("active", active);
|
||||
if (!toItem) {
|
||||
nbt.setBoolean("active", active);
|
||||
}
|
||||
nbt.setBoolean("latching", latching);
|
||||
nbt.setInteger("rsChannel", rsOutputChannel);
|
||||
nbt.setInteger("rsId", rsOutputId);
|
||||
|
|
|
@ -51,7 +51,7 @@ public abstract class PanelComponent {
|
|||
baseCreaters.put("indicator_light", IndicatorLight::new);
|
||||
baseCreaters.put("slider", Slider::new);
|
||||
}
|
||||
protected abstract void writeCustomNBT(NBTTagCompound nbt);
|
||||
protected abstract void writeCustomNBT(NBTTagCompound nbt, boolean toItem);
|
||||
protected abstract void readCustomNBT(NBTTagCompound nbt);
|
||||
// DON'T OFFSET BY x, y IN THIS METHOD!
|
||||
public abstract List<RawQuad> getQuads();
|
||||
|
@ -96,8 +96,8 @@ public abstract class PanelComponent {
|
|||
this.panelHeight = panelHeight;
|
||||
}
|
||||
|
||||
public void writeToNBT(NBTTagCompound nbt) {
|
||||
writeCustomNBT(nbt);
|
||||
public void writeToNBT(NBTTagCompound nbt, boolean toItem) {
|
||||
writeCustomNBT(nbt, toItem);
|
||||
nbt.setFloat("x", getX());
|
||||
nbt.setFloat("y", getY());
|
||||
nbt.setFloat("panelHeight", panelHeight);
|
||||
|
|
|
@ -36,10 +36,12 @@ public class Slider extends PanelComponent {
|
|||
super("slider");
|
||||
}
|
||||
@Override
|
||||
protected void writeCustomNBT(NBTTagCompound nbt) {
|
||||
protected void writeCustomNBT(NBTTagCompound nbt, boolean toItem) {
|
||||
nbt.setInteger("color", color);
|
||||
nbt.setFloat("length", length);
|
||||
nbt.setByte("output", out);
|
||||
if (!toItem) {
|
||||
nbt.setByte("output", out);
|
||||
}
|
||||
nbt.setByte("rsChannel", rsChannel);
|
||||
nbt.setInteger("rsId", rsId);
|
||||
nbt.setBoolean("horizontal", horizontal);
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
|
||||
package malte0811.industrialWires.blocks.controlpanel;
|
||||
|
||||
import blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces;
|
||||
import blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IDirectionalTile;
|
||||
import blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IPlayerInteraction;
|
||||
import blusunrize.immersiveengineering.common.util.chickenbones.Matrix4;
|
||||
|
@ -50,31 +51,32 @@ import java.util.HashSet;
|
|||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class TileEntityPanel extends TileEntityIWBase implements IDirectionalTile, IBlockBoundsIW, IPlayerInteraction, ITickable {
|
||||
public class TileEntityPanel extends TileEntityIWBase implements IDirectionalTile, IBlockBoundsIW, IPlayerInteraction, ITickable, IEBlockInterfaces.ITileDrop {
|
||||
private PropertyComponents.PanelRenderProperties components = new PropertyComponents.PanelRenderProperties();
|
||||
private boolean firstTick = true;
|
||||
// non-rendered properties
|
||||
private Set<TileEntityRSPanelConn> rsPorts = new HashSet<>();
|
||||
|
||||
{
|
||||
for (int i = 2;i<14;i++) {
|
||||
int color = EnumDyeColor.byMetadata(i-2).getMapColor().colorValue;
|
||||
IndicatorLight ind = new IndicatorLight(0, i-2, color);
|
||||
LightedButton btn = new LightedButton(color, false, true, 1, i-2);
|
||||
for (int i = 2; i < 14; i++) {
|
||||
int color = EnumDyeColor.byMetadata(i - 2).getMapColor().colorValue;
|
||||
IndicatorLight ind = new IndicatorLight(0, i - 2, color);
|
||||
LightedButton btn = new LightedButton(color, false, true, 1, i - 2);
|
||||
Label lbl = new Label("->", color);
|
||||
ind.setX(0);
|
||||
ind.setY(i/16F);
|
||||
ind.setY(i / 16F);
|
||||
ind.setPanelHeight(components.height);
|
||||
lbl.setX(2/16F);
|
||||
lbl.setY(i/16F);
|
||||
lbl.setX(2 / 16F);
|
||||
lbl.setY(i / 16F);
|
||||
lbl.setPanelHeight(components.height);
|
||||
btn.setX(5/16F);
|
||||
btn.setY(i/16F);
|
||||
btn.setX(5 / 16F);
|
||||
btn.setY(i / 16F);
|
||||
btn.setPanelHeight(components.height);
|
||||
components.add(ind);
|
||||
components.add(lbl);
|
||||
components.add(btn);
|
||||
}
|
||||
Slider slid = new Slider(.5F, 0x00ff00, true, 1, (byte)1);
|
||||
Slider slid = new Slider(.5F, 0x00ff00, true, 1, (byte) 1);
|
||||
slid.setX(.4F);
|
||||
slid.setY(.25F);
|
||||
slid.setPanelHeight(components.height);
|
||||
|
@ -83,13 +85,13 @@ public class TileEntityPanel extends TileEntityIWBase implements IDirectionalTil
|
|||
|
||||
@Override
|
||||
public void update() {
|
||||
for (PanelComponent pc:components) {
|
||||
for (PanelComponent pc : components) {
|
||||
pc.update(this);
|
||||
}
|
||||
if (!worldObj.isRemote) {
|
||||
if (firstTick) {
|
||||
List<BlockPos> parts = MiscUtils.discoverPanelParts(worldObj, pos);
|
||||
for (BlockPos bp:parts) {
|
||||
for (BlockPos bp : parts) {
|
||||
TileEntity te = worldObj.getTileEntity(bp);
|
||||
if (te instanceof TileEntityRSPanelConn) {
|
||||
((TileEntityRSPanelConn) te).registerPanel(this);
|
||||
|
@ -102,34 +104,58 @@ public class TileEntityPanel extends TileEntityIWBase implements IDirectionalTil
|
|||
|
||||
@Override
|
||||
public void writeNBT(NBTTagCompound out, boolean updatePacket) {
|
||||
NBTTagList comps = new NBTTagList();
|
||||
for (PanelComponent p:components) {
|
||||
NBTTagCompound nbt = new NBTTagCompound();
|
||||
p.writeToNBT(nbt);
|
||||
comps.appendTag(nbt);
|
||||
}
|
||||
out.setTag("components", comps);
|
||||
writeToItemNBT(out, false);
|
||||
out.setInteger("facing", components.facing.getHorizontalIndex());
|
||||
out.setFloat("height", components.height);
|
||||
out.setInteger("top", components.top.getIndex());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readNBT(NBTTagCompound in, boolean updatePacket) {
|
||||
NBTTagList l = in.getTagList("components", 10);
|
||||
readFromItemNBT(in);
|
||||
components.facing = EnumFacing.getHorizontal(in.getInteger("facing"));
|
||||
components.top = EnumFacing.getFront(in.getInteger("top"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getTileDrop(EntityPlayer player, IBlockState state) {
|
||||
NBTTagCompound ret = new NBTTagCompound();
|
||||
writeToItemNBT(ret, true);
|
||||
ItemStack retStack = new ItemStack(IndustrialWires.panel, 1, BlockTypes_Panel.TOP.ordinal());
|
||||
retStack.setTagCompound(ret);
|
||||
return retStack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readOnPlacement(@Nullable EntityLivingBase placer, ItemStack stack) {
|
||||
if (stack.hasTagCompound()) {
|
||||
readFromItemNBT(stack.getTagCompound());
|
||||
}
|
||||
}
|
||||
|
||||
public void readFromItemNBT(NBTTagCompound nbt) {
|
||||
NBTTagList l = nbt.getTagList("components", 10);
|
||||
components.clear();
|
||||
for (int i = 0;i<l.tagCount();i++) {
|
||||
for (int i = 0; i < l.tagCount(); i++) {
|
||||
PanelComponent pc = PanelComponent.read(l.getCompoundTagAt(i));
|
||||
if (pc!=null) {
|
||||
if (pc != null) {
|
||||
components.add(pc);
|
||||
}
|
||||
}
|
||||
components.facing = EnumFacing.getHorizontal(in.getInteger("facing"));
|
||||
components.height = in.getFloat("height");
|
||||
components.top = EnumFacing.getFront(in.getInteger("top"));
|
||||
components.height = nbt.getFloat("height");
|
||||
defAABB = null;
|
||||
}
|
||||
|
||||
public void writeToItemNBT(NBTTagCompound nbt, boolean toItem) {
|
||||
NBTTagList comps = new NBTTagList();
|
||||
for (PanelComponent p : components) {
|
||||
NBTTagCompound nbtInner = new NBTTagCompound();
|
||||
p.writeToNBT(nbtInner, toItem);
|
||||
comps.appendTag(nbtInner);
|
||||
}
|
||||
nbt.setTag("components", comps);
|
||||
nbt.setFloat("height", components.height);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnumFacing getFacing() {
|
||||
return components.facing;
|
||||
|
@ -180,9 +206,10 @@ public class TileEntityPanel extends TileEntityIWBase implements IDirectionalTil
|
|||
}
|
||||
|
||||
private AxisAlignedBB defAABB;
|
||||
|
||||
@Override
|
||||
public AxisAlignedBB getBoundingBox() {
|
||||
if (defAABB==null) {
|
||||
if (defAABB == null) {
|
||||
defAABB = apply(components.getPanelBaseTransform(), new AxisAlignedBB(0, 0, 0, 1, components.getMaxHeight(), 1));
|
||||
}
|
||||
return defAABB;
|
||||
|
@ -191,6 +218,7 @@ public class TileEntityPanel extends TileEntityIWBase implements IDirectionalTil
|
|||
public PropertyComponents.PanelRenderProperties getComponents() {
|
||||
return components;
|
||||
}
|
||||
|
||||
public AxisAlignedBB apply(Matrix4 mat, AxisAlignedBB in) {
|
||||
Vec3d min = new Vec3d(in.minX, in.minY, in.minZ);
|
||||
Vec3d max = new Vec3d(in.maxX, in.maxY, in.maxZ);
|
||||
|
@ -207,19 +235,19 @@ public class TileEntityPanel extends TileEntityIWBase implements IDirectionalTil
|
|||
Vec3d playerPos = Minecraft.getMinecraft().thePlayer.getPositionVector().addVector(-pos.getX(), player.getEyeHeight() - pos.getY(), -pos.getZ());
|
||||
for (PanelComponent pc : components) {
|
||||
AxisAlignedBB box = pc.getBlockRelativeAABB();
|
||||
if (box!=null) {
|
||||
if (box != null) {
|
||||
box = apply(mat, box.expandXyz(.002));
|
||||
Vec3d hitVec = hitAbs ? hit.addVector(-pos.getX(), -pos.getY(), -pos.getZ()) : hit;
|
||||
hitVec = hitVec.scale(2).subtract(playerPos);
|
||||
RayTraceResult ray = box.calculateIntercept(playerPos, hitVec);
|
||||
if (ray != null) {
|
||||
if (retPc==null) {
|
||||
if (retPc == null) {
|
||||
retPc = pc;
|
||||
retRay = ray;
|
||||
} else {
|
||||
double oldDist = retRay.hitVec.subtract(playerPos).lengthSquared();
|
||||
double newDist = ray.hitVec.subtract(playerPos).lengthSquared();
|
||||
if (newDist<oldDist) {
|
||||
if (newDist < oldDist) {
|
||||
retPc = pc;
|
||||
retRay = ray;
|
||||
}
|
||||
|
@ -227,7 +255,7 @@ public class TileEntityPanel extends TileEntityIWBase implements IDirectionalTil
|
|||
}
|
||||
}
|
||||
}
|
||||
return retPc!=null?new ImmutablePair<>(retPc, retRay):null;
|
||||
return retPc != null ? new ImmutablePair<>(retPc, retRay) : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -247,20 +275,21 @@ public class TileEntityPanel extends TileEntityIWBase implements IDirectionalTil
|
|||
}
|
||||
|
||||
public void interactServer(Vec3d hitRelative, int pcId) {
|
||||
if (pcId>=0&&pcId<components.size()) {
|
||||
if (pcId >= 0 && pcId < components.size()) {
|
||||
components.get(pcId).interactWith(hitRelative, this);
|
||||
}
|
||||
}
|
||||
|
||||
public void triggerRenderUpdate() {
|
||||
IBlockState state = worldObj.getBlockState(pos);
|
||||
worldObj.notifyBlockUpdate(pos,state,state,3);
|
||||
worldObj.notifyBlockUpdate(pos, state, state, 3);
|
||||
worldObj.addBlockEvent(pos, state.getBlock(), 255, 0);
|
||||
}
|
||||
|
||||
public void registerRS(TileEntityRSPanelConn te) {
|
||||
rsPorts.add(te);
|
||||
}
|
||||
|
||||
public void unregisterRS(TileEntityRSPanelConn te) {
|
||||
rsPorts.remove(te);
|
||||
}
|
||||
|
@ -268,7 +297,7 @@ public class TileEntityPanel extends TileEntityIWBase implements IDirectionalTil
|
|||
@Override
|
||||
public void onChunkUnload() {
|
||||
super.onChunkUnload();
|
||||
for (TileEntityRSPanelConn rs:rsPorts) {
|
||||
for (TileEntityRSPanelConn rs : rsPorts) {
|
||||
rs.unregisterPanel(this, true);
|
||||
}
|
||||
}
|
||||
|
@ -276,7 +305,7 @@ public class TileEntityPanel extends TileEntityIWBase implements IDirectionalTil
|
|||
@Override
|
||||
public void invalidate() {
|
||||
super.invalidate();
|
||||
for (TileEntityRSPanelConn rs:rsPorts) {
|
||||
for (TileEntityRSPanelConn rs : rsPorts) {
|
||||
rs.unregisterPanel(this, true);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,8 +7,10 @@ import blusunrize.immersiveengineering.api.energy.wires.TileEntityImmersiveConne
|
|||
import blusunrize.immersiveengineering.api.energy.wires.WireType;
|
||||
import blusunrize.immersiveengineering.api.energy.wires.redstone.IRedstoneConnector;
|
||||
import blusunrize.immersiveengineering.api.energy.wires.redstone.RedstoneWireNetwork;
|
||||
import malte0811.industrialWires.blocks.INetGUI;
|
||||
import malte0811.industrialWires.util.MiscUtils;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.ITickable;
|
||||
|
@ -17,14 +19,11 @@ import net.minecraft.util.math.Vec3d;
|
|||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class TileEntityRSPanelConn extends TileEntityImmersiveConnectable implements IRedstoneConnector, ITickable {
|
||||
public class TileEntityRSPanelConn extends TileEntityImmersiveConnectable implements IRedstoneConnector, ITickable, INetGUI {
|
||||
private byte[] out = new byte[16];
|
||||
private boolean dirty = true;
|
||||
private byte[] oldInput = new byte[16];
|
||||
|
@ -205,4 +204,32 @@ public class TileEntityRSPanelConn extends TileEntityImmersiveConnectable implem
|
|||
unregisterPanel(panel, false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChange(NBTTagCompound nbt, EntityPlayer p) {
|
||||
if (nbt.hasKey("rsId")) {
|
||||
List<BlockPos> parts = MiscUtils.discoverPanelParts(worldObj, pos);
|
||||
List<TileEntityPanel> tes = new ArrayList<>(parts.size());
|
||||
for (BlockPos bp:parts) {
|
||||
TileEntity te = worldObj.getTileEntity(bp);
|
||||
if (te instanceof TileEntityPanel) {
|
||||
tes.add((TileEntityPanel) te);
|
||||
unregisterPanel((TileEntityPanel) te, true);
|
||||
}
|
||||
}
|
||||
id = nbt.getInteger("rsId");
|
||||
out = new byte[16];
|
||||
for (TileEntityPanel panel:tes) {
|
||||
registerPanel(panel);
|
||||
}
|
||||
network.updateValues();
|
||||
IBlockState state = worldObj.getBlockState(pos);
|
||||
worldObj.notifyBlockUpdate(pos, state, state, 3);
|
||||
worldObj.addBlockEvent(pos, state.getBlock(), 255, 0);
|
||||
}
|
||||
}
|
||||
|
||||
public int getRsId() {
|
||||
return id;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,6 +31,8 @@ import malte0811.industrialWires.IWConfig;
|
|||
import malte0811.industrialWires.IndustrialWires;
|
||||
import malte0811.industrialWires.blocks.IMetaEnum;
|
||||
import malte0811.industrialWires.blocks.TileEntityJacobsLadder;
|
||||
import malte0811.industrialWires.blocks.controlpanel.TileEntityRSPanelConn;
|
||||
import malte0811.industrialWires.client.gui.RSPanelConn;
|
||||
import malte0811.industrialWires.client.panelmodel.PanelModelLoader;
|
||||
import malte0811.industrialWires.client.render.TileRenderJacobsLadder;
|
||||
import malte0811.industrialWires.items.ItemIC2Coil;
|
||||
|
@ -40,8 +42,10 @@ import net.minecraft.client.audio.ISound;
|
|||
import net.minecraft.client.audio.PositionedSoundRecord;
|
||||
import net.minecraft.client.renderer.block.model.ModelBakery;
|
||||
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.SoundCategory;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
@ -213,4 +217,13 @@ public class ClientProxy extends CommonProxy {
|
|||
ClientUtils.mc().getSoundHandler().playSound(sound);
|
||||
playingSounds.put(te.getPos(), sound);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
|
||||
TileEntity te = world.getTileEntity(new BlockPos(x, y, z));
|
||||
if (te instanceof TileEntityRSPanelConn) {
|
||||
return new RSPanelConn((TileEntityRSPanelConn)te);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,71 @@
|
|||
package malte0811.industrialWires.client.gui;
|
||||
|
||||
import malte0811.industrialWires.IndustrialWires;
|
||||
import malte0811.industrialWires.blocks.controlpanel.TileEntityRSPanelConn;
|
||||
import malte0811.industrialWires.network.MessageGUIInteract;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.GuiLabel;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class RSPanelConn extends GuiScreen {
|
||||
private TileEntityRSPanelConn te;
|
||||
private int curr = 0;
|
||||
public RSPanelConn(TileEntityRSPanelConn tile) {
|
||||
te = tile;
|
||||
}
|
||||
@Override
|
||||
public void initGui() {
|
||||
super.initGui();
|
||||
buttonList.clear();
|
||||
buttonList.add(new GuiButton(0, width/2-8, height/2-32, 16, 16, "+1"));
|
||||
buttonList.add(new GuiButton(1, width/2-8, height/2+32, 16, 16, "-1"));
|
||||
buttonList.add(new GuiButton(2, width/2-8, height/2+48, 16, 16, "Ok"));
|
||||
curr = te.getRsId();
|
||||
onChange();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void actionPerformed(GuiButton button) throws IOException {
|
||||
super.actionPerformed(button);
|
||||
switch (button.id) {
|
||||
case 0:
|
||||
curr++;
|
||||
onChange();
|
||||
break;
|
||||
case 1:
|
||||
curr--;
|
||||
onChange();
|
||||
break;
|
||||
case 2:
|
||||
mc.displayGuiScreen(null);
|
||||
mc.setIngameFocus();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawBackground(int tint) {
|
||||
super.drawBackground(tint);
|
||||
//TODO proper background
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean doesGuiPauseGame() {
|
||||
return false;
|
||||
}
|
||||
|
||||
private void onChange() {
|
||||
curr = Math.max(0, curr);
|
||||
labelList.clear();
|
||||
labelList.add(new GuiLabel(mc.fontRendererObj, 0, width/2-8, height/2-8, 16, 16, 0xff0000));
|
||||
labelList.get(0).addLine(Integer.toString(curr));
|
||||
if (curr!=te.getRsId()) {
|
||||
NBTTagCompound nbt = new NBTTagCompound();
|
||||
nbt.setInteger("rsId", curr);
|
||||
IndustrialWires.packetHandler.sendToServer(new MessageGUIInteract(te, nbt));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,73 @@
|
|||
/*
|
||||
* This file is part of Industrial Wires.
|
||||
* Copyright (C) 2016-2017 malte0811
|
||||
*
|
||||
* Industrial Wires is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Industrial Wires is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Industrial Wires. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package malte0811.industrialWires.network;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import malte0811.industrialWires.blocks.INetGUI;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraftforge.fml.common.network.ByteBufUtils;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
|
||||
|
||||
public class MessageGUIInteract implements IMessage {
|
||||
private BlockPos pos;
|
||||
private NBTTagCompound data;
|
||||
|
||||
public MessageGUIInteract(TileEntity tile, NBTTagCompound data) {
|
||||
pos = tile.getPos();
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public MessageGUIInteract() {}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
this.pos = new BlockPos(buf.readInt(), buf.readInt(), buf.readInt());
|
||||
data = ByteBufUtils.readTag(buf);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
buf.writeInt(this.pos.getX());
|
||||
buf.writeInt(this.pos.getY());
|
||||
buf.writeInt(this.pos.getZ());
|
||||
ByteBufUtils.writeTag(buf, data);
|
||||
}
|
||||
|
||||
public static class HandlerServer implements IMessageHandler<MessageGUIInteract, IMessage> {
|
||||
@Override
|
||||
public IMessage onMessage(MessageGUIInteract message, MessageContext ctx) {
|
||||
ctx.getServerHandler().playerEntity.getServerWorld().addScheduledTask(()->handle(message, ctx.getServerHandler().playerEntity));
|
||||
return null;
|
||||
}
|
||||
private void handle(MessageGUIInteract msg, EntityPlayerMP player) {
|
||||
if (player.getDistanceSqToCenter(msg.pos)<100) {//closer than 10 blocks TODO use player reach distance?
|
||||
TileEntity te = player.worldObj.getTileEntity(msg.pos);
|
||||
if (te instanceof INetGUI) {
|
||||
((INetGUI) te).onChange(msg.data, player);
|
||||
te.markDirty();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue