mirror of
https://github.com/GTNewHorizons/Draconic-Evolution.git
synced 2026-10-26 14:24:14 +00:00
Compare commits
6
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
aa49ba56ac | ||
|
|
426837a212 | ||
|
|
dd3366bdc3 | ||
|
|
c437a2a440 | ||
|
|
ca32c00962 | ||
|
|
e82e89b7ba |
No files matched your search
+229
@@ -0,0 +1,229 @@
|
||||
package com.brandon3055.draconicevolution.client.gui;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.StatCollector;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import com.brandon3055.draconicevolution.DraconicEvolution;
|
||||
import com.brandon3055.draconicevolution.common.container.ContainerDislocatorInhibitor;
|
||||
import com.brandon3055.draconicevolution.common.inventory.SlotFakeItem;
|
||||
import com.brandon3055.draconicevolution.common.lib.References;
|
||||
import com.brandon3055.draconicevolution.common.network.DislocatorInhibitorButtonPacket;
|
||||
import com.brandon3055.draconicevolution.common.network.SlotFakeClickPacket;
|
||||
import com.brandon3055.draconicevolution.common.tileentities.TileDislocatorInhibitor;
|
||||
|
||||
import codechicken.nei.VisiblityData;
|
||||
import codechicken.nei.api.INEIGuiHandler;
|
||||
import codechicken.nei.api.TaggedInventoryArea;
|
||||
import cpw.mods.fml.common.Optional;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Optional.Interface(iface = "codechicken.nei.api.INEIGuiHandler", modid = "NotEnoughItems")
|
||||
public class GUIDislocatorInhibitor extends GuiContainer implements INEIGuiHandler {
|
||||
|
||||
private static final ResourceLocation texture = new ResourceLocation(
|
||||
References.MODID.toLowerCase(),
|
||||
"textures/gui/Inhibitor.png");
|
||||
private int range = 5;
|
||||
private TileDislocatorInhibitor.ActivityControlType activityControlType = TileDislocatorInhibitor.ActivityControlType.ALWAYS_ACTIVE;
|
||||
private boolean whitelist = false;
|
||||
|
||||
private final ContainerDislocatorInhibitor container;
|
||||
|
||||
public GUIDislocatorInhibitor(InventoryPlayer playerInventory, TileDislocatorInhibitor inhibitor) {
|
||||
super(inhibitor.getGuiContainer(playerInventory));
|
||||
this.container = (ContainerDislocatorInhibitor) inventorySlots;
|
||||
|
||||
xSize = 176;
|
||||
ySize = 142;
|
||||
|
||||
syncWithServer();
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public void initGui() {
|
||||
super.initGui();
|
||||
buttonList.clear();
|
||||
buttonList.add(new GuiButtonAHeight(0, guiLeft + 7, guiTop + 11, 18, 18, "-"));
|
||||
buttonList.add(new GuiButtonAHeight(1, guiLeft + 97, guiTop + 11, 18, 18, "+"));
|
||||
buttonList.add(new GuiButtonAHeight(2, guiLeft + 151, guiTop + 11, 18, 18, ""));
|
||||
buttonList.add(new GuiButtonAHeight(3, guiLeft + 151, guiTop + 33, 18, 18, ""));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawGuiContainerForegroundLayer(int x, int y) {
|
||||
drawGuiText();
|
||||
drawGreyOutSlots();
|
||||
drawButtonIcons();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) {
|
||||
|
||||
GL11.glColor4f(1, 1, 1, 1);
|
||||
|
||||
Minecraft.getMinecraft().getTextureManager().bindTexture(texture);
|
||||
drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, ySize);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawScreen(int x, int y, float partialTicks) {
|
||||
super.drawScreen(x, y, partialTicks);
|
||||
ArrayList<String> lines = new ArrayList<>();
|
||||
if ((x - guiLeft > 7 && x - guiLeft < 25) && (y - guiTop > 11 && y - guiTop < 29)) {
|
||||
lines.add(StatCollector.translateToLocal("gui.de.dislocatorInhibitor.tooltip.range.increase.txt"));
|
||||
} else if ((x - guiLeft > 97 && x - guiLeft < 115) && (y - guiTop > 11 && y - guiTop < 29)) {
|
||||
lines.add(StatCollector.translateToLocal("gui.de.dislocatorInhibitor.tooltip.range.decrease.txt"));
|
||||
} else if ((x - guiLeft > 151 && x - guiLeft < 169) && (y - guiTop > 11 && y - guiTop < 29)) {
|
||||
switch (activityControlType) {
|
||||
case ALWAYS_ACTIVE -> lines
|
||||
.add(StatCollector.translateToLocal("gui.de.dislocatorInhibitor.tooltip.activity.always.txt"));
|
||||
case WITH_REDSTONE -> lines
|
||||
.add(StatCollector.translateToLocal("gui.de.dislocatorInhibitor.tooltip.activity.with.txt"));
|
||||
case WITHOUT_REDSTONE -> lines
|
||||
.add(StatCollector.translateToLocal("gui.de.dislocatorInhibitor.tooltip.activity.without.txt"));
|
||||
case NEVER_ACTIVE -> lines
|
||||
.add(StatCollector.translateToLocal("gui.de.dislocatorInhibitor.tooltip.activity.never.txt"));
|
||||
}
|
||||
lines.add(StatCollector.translateToLocal("gui.de.dislocatorInhibitor.tooltip.activity.cycle.txt"));
|
||||
} else if ((x - guiLeft > 151 && x - guiLeft < 169) && (y - guiTop > 33 && y - guiTop < 51)) {
|
||||
if (whitelist) {
|
||||
lines.add(StatCollector.translateToLocal("gui.de.dislocatorInhibitor.tooltip.whitelist.txt"));
|
||||
} else {
|
||||
lines.add(StatCollector.translateToLocal("gui.de.dislocatorInhibitor.tooltip.blacklist.txt"));
|
||||
}
|
||||
}
|
||||
if (!lines.isEmpty()) {
|
||||
drawHoveringText(lines, x, y, fontRendererObj);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handleMouseClick(Slot slotIn, int slotId, int clickedButton, int clickType) {
|
||||
if (slotIn instanceof SlotFakeItem sfi) {
|
||||
DraconicEvolution.network.sendToServer(
|
||||
new SlotFakeClickPacket((byte) sfi.getSlotIndex(), this.mc.thePlayer.inventory.getItemStack()));
|
||||
} else {
|
||||
super.handleMouseClick(slotIn, slotId, clickedButton, clickType);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void actionPerformed(GuiButton button) {
|
||||
switch (button.id) {
|
||||
case 0 -> { // Range -
|
||||
range = Math.max(range - 1, TileDislocatorInhibitor.MINIMUM_RANGE);
|
||||
DraconicEvolution.network.sendToServer(new DislocatorInhibitorButtonPacket((byte) 0, (byte) range));
|
||||
}
|
||||
case 1 -> { // Range +
|
||||
range = Math.min(range + 1, TileDislocatorInhibitor.MAXIMUM_RANGE);
|
||||
DraconicEvolution.network.sendToServer(new DislocatorInhibitorButtonPacket((byte) 0, (byte) range));
|
||||
}
|
||||
case 2 -> { // Cycle Activity control
|
||||
activityControlType = activityControlType.getNext();
|
||||
byte controlMode = (byte) (activityControlType.ordinal());
|
||||
DraconicEvolution.network.sendToServer(new DislocatorInhibitorButtonPacket((byte) 1, controlMode));
|
||||
}
|
||||
case 3 -> { // Toggle Whitelist/Blacklist mode
|
||||
whitelist = !whitelist;
|
||||
byte whitelistMode = (byte) (whitelist ? 1 : 0);
|
||||
DraconicEvolution.network.sendToServer(new DislocatorInhibitorButtonPacket((byte) 2, whitelistMode));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public VisiblityData modifyVisiblity(GuiContainer gui, VisiblityData currentVisibility) {
|
||||
return currentVisibility;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<Integer> getItemSpawnSlots(GuiContainer gui, ItemStack item) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TaggedInventoryArea> getInventoryAreas(GuiContainer gui) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handleDragNDrop(GuiContainer gui, int mousex, int mousey, ItemStack draggedStack, int button) {
|
||||
if (gui instanceof GUIDislocatorInhibitor) {
|
||||
for (var slot : container.inventorySlots) {
|
||||
if (slot instanceof SlotFakeItem sfi) {
|
||||
if (sfi.isOverSlot(mousex - this.guiLeft, mousey - this.guiTop)) {
|
||||
draggedStack.stackSize = 0;
|
||||
DraconicEvolution.network
|
||||
.sendToServer(new SlotFakeClickPacket((byte) sfi.getSlotIndex(), draggedStack));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hideItemPanelSlot(GuiContainer gui, int x, int y, int w, int h) {
|
||||
return false;
|
||||
}
|
||||
|
||||
private void drawGuiText() {
|
||||
fontRendererObj.drawString(
|
||||
StatCollector.translateToLocal("gui.de.dislocatorInhibitor.range.txt"),
|
||||
40,
|
||||
17,
|
||||
0x000000,
|
||||
false);
|
||||
fontRendererObj.drawString(String.valueOf(range), range < 10 ? 78 : 75, 17, 0x000000, false);
|
||||
}
|
||||
|
||||
private void drawButtonIcons() {
|
||||
GL11.glColor4f(1, 1, 1, 1);
|
||||
|
||||
Minecraft.getMinecraft().getTextureManager().bindTexture(texture);
|
||||
|
||||
// activity control button
|
||||
drawTexturedModalRect(151, 11, 0, 142 + (18 * activityControlType.ordinal()), 18, 18);
|
||||
|
||||
// whitelist button
|
||||
drawTexturedModalRect(151, 33, 18, 142 + (whitelist ? 0 : 18), 18, 18);
|
||||
}
|
||||
|
||||
private void drawGreyOutSlots() {
|
||||
|
||||
GL11.glDisable(GL11.GL_LIGHTING);
|
||||
GL11.glDisable(GL11.GL_DEPTH_TEST);
|
||||
GL11.glEnable(GL11.GL_BLEND);
|
||||
GL11.glColor4f(1.0F, 1.0F, 1.0F, 0.5f);
|
||||
Minecraft.getMinecraft().getTextureManager().bindTexture(texture);
|
||||
for (int i = 0; i < 8; i++) {
|
||||
drawTexturedModalRect(7 + i * 18, 33, 36, 142, 18, 18);
|
||||
}
|
||||
GL11.glDisable(GL11.GL_BLEND);
|
||||
GL11.glEnable(GL11.GL_DEPTH_TEST);
|
||||
GL11.glEnable(GL11.GL_LIGHTING);
|
||||
}
|
||||
|
||||
private void syncWithServer() {
|
||||
TileDislocatorInhibitor inhibitor = container.getTileEntity();
|
||||
whitelist = inhibitor.isWhitelist();
|
||||
range = inhibitor.getRange();
|
||||
activityControlType = inhibitor.getActivityControlType();
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,7 @@ import com.brandon3055.draconicevolution.client.gui.componentguis.GUIManual;
|
||||
import com.brandon3055.draconicevolution.client.gui.componentguis.GUIReactor;
|
||||
import com.brandon3055.draconicevolution.client.gui.componentguis.GUIToolConfig;
|
||||
import com.brandon3055.draconicevolution.common.container.ContainerAdvTool;
|
||||
import com.brandon3055.draconicevolution.common.container.ContainerDislocatorInhibitor;
|
||||
import com.brandon3055.draconicevolution.common.container.ContainerDissEnchanter;
|
||||
import com.brandon3055.draconicevolution.common.container.ContainerDraconiumChest;
|
||||
import com.brandon3055.draconicevolution.common.container.ContainerEnergyInfuser;
|
||||
@@ -20,6 +21,7 @@ import com.brandon3055.draconicevolution.common.container.ContainerSunDial;
|
||||
import com.brandon3055.draconicevolution.common.container.ContainerUpgradeModifier;
|
||||
import com.brandon3055.draconicevolution.common.container.ContainerWeatherController;
|
||||
import com.brandon3055.draconicevolution.common.inventory.InventoryTool;
|
||||
import com.brandon3055.draconicevolution.common.tileentities.TileDislocatorInhibitor;
|
||||
import com.brandon3055.draconicevolution.common.tileentities.TileDissEnchanter;
|
||||
import com.brandon3055.draconicevolution.common.tileentities.TileDraconiumChest;
|
||||
import com.brandon3055.draconicevolution.common.tileentities.TileEnergyInfuser;
|
||||
@@ -53,6 +55,7 @@ public class GuiHandler implements IGuiHandler {
|
||||
public static final int GUIID_FLOW_GATE = 13;
|
||||
public static final int GUIID_REACTOR = 14;
|
||||
public static final int GUIID_UPGRADE_MODIFIER = 15;
|
||||
public static final int GUIID_DISLOCATOR_INHIBITOR = 16;
|
||||
public static final int GUIID_CONTAINER_TEMPLATE = 100;
|
||||
|
||||
public GuiHandler() {
|
||||
@@ -116,6 +119,11 @@ public class GuiHandler implements IGuiHandler {
|
||||
return new ContainerUpgradeModifier(player.inventory, upgradeModifier);
|
||||
}
|
||||
}
|
||||
case GUIID_DISLOCATOR_INHIBITOR -> {
|
||||
if (tile instanceof TileDislocatorInhibitor inhibitor) {
|
||||
return new ContainerDislocatorInhibitor(player.inventory, inhibitor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
@@ -199,6 +207,11 @@ public class GuiHandler implements IGuiHandler {
|
||||
new ContainerUpgradeModifier(player.inventory, upgradeModifier));
|
||||
}
|
||||
}
|
||||
case GUIID_DISLOCATOR_INHIBITOR -> {
|
||||
if (tile instanceof TileDislocatorInhibitor inhibitor) {
|
||||
return new GUIDislocatorInhibitor(player.inventory, inhibitor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
@@ -38,6 +38,7 @@ import com.brandon3055.draconicevolution.common.magic.PotionHandler;
|
||||
import com.brandon3055.draconicevolution.common.network.BlockUpdatePacket;
|
||||
import com.brandon3055.draconicevolution.common.network.ButtonPacket;
|
||||
import com.brandon3055.draconicevolution.common.network.ContributorPacket;
|
||||
import com.brandon3055.draconicevolution.common.network.DislocatorInhibitorButtonPacket;
|
||||
import com.brandon3055.draconicevolution.common.network.GenericParticlePacket;
|
||||
import com.brandon3055.draconicevolution.common.network.ItemConfigPacket;
|
||||
import com.brandon3055.draconicevolution.common.network.MagnetToggleAckPacket;
|
||||
@@ -48,6 +49,7 @@ import com.brandon3055.draconicevolution.common.network.PlacedItemPacket;
|
||||
import com.brandon3055.draconicevolution.common.network.PlayerDetectorButtonPacket;
|
||||
import com.brandon3055.draconicevolution.common.network.PlayerDetectorStringPacket;
|
||||
import com.brandon3055.draconicevolution.common.network.ShieldHitPacket;
|
||||
import com.brandon3055.draconicevolution.common.network.SlotFakeClickPacket;
|
||||
import com.brandon3055.draconicevolution.common.network.SpeedRequestPacket;
|
||||
import com.brandon3055.draconicevolution.common.network.TeleporterPacket;
|
||||
import com.brandon3055.draconicevolution.common.network.TileObjectPacket;
|
||||
@@ -211,6 +213,13 @@ public class CommonProxy {
|
||||
.registerMessage(MagnetTogglePacket.Handler.class, MagnetTogglePacket.class, 19, Side.SERVER);
|
||||
DraconicEvolution.network
|
||||
.registerMessage(MagnetToggleAckPacket.Handler.class, MagnetToggleAckPacket.class, 20, Side.CLIENT);
|
||||
DraconicEvolution.network.registerMessage(
|
||||
DislocatorInhibitorButtonPacket.Handler.class,
|
||||
DislocatorInhibitorButtonPacket.class,
|
||||
21,
|
||||
Side.SERVER);
|
||||
DraconicEvolution.network
|
||||
.registerMessage(SlotFakeClickPacket.Handler.class, SlotFakeClickPacket.class, 22, Side.SERVER);
|
||||
}
|
||||
|
||||
public void registerTileEntities() {
|
||||
|
||||
+52
-8
@@ -1,22 +1,29 @@
|
||||
package com.brandon3055.draconicevolution.common.blocks.machine;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.ITileEntityProvider;
|
||||
import net.minecraft.client.renderer.texture.IIconRegister;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemBlock;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.ChatComponentText;
|
||||
import net.minecraft.util.EnumChatFormatting;
|
||||
import net.minecraft.util.StatCollector;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import com.brandon3055.draconicevolution.DraconicEvolution;
|
||||
import com.brandon3055.draconicevolution.client.gui.GuiHandler;
|
||||
import com.brandon3055.draconicevolution.common.ModBlocks;
|
||||
import com.brandon3055.draconicevolution.common.blocks.BlockDE;
|
||||
import com.brandon3055.draconicevolution.common.lib.References;
|
||||
import com.brandon3055.draconicevolution.common.lib.Strings;
|
||||
import com.brandon3055.draconicevolution.common.tileentities.TileDislocatorInhibitor;
|
||||
|
||||
import cpw.mods.fml.common.network.internal.FMLNetworkHandler;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
@@ -26,7 +33,7 @@ public class DislocatorInhibitor extends BlockDE implements ITileEntityProvider
|
||||
this.setBlockName(Strings.dislocatorInhibitor);
|
||||
this.setCreativeTab(DraconicEvolution.tabBlocksItems);
|
||||
this.setStepSound(soundTypeStone);
|
||||
ModBlocks.register(this);
|
||||
ModBlocks.register(this, InfusedObsidianItemBlock.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -50,20 +57,43 @@ public class DislocatorInhibitor extends BlockDE implements ITileEntityProvider
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float prx,
|
||||
float pry, float prz) {
|
||||
public boolean canConnectRedstone(IBlockAccess world, int x, int y, int z, int side) {
|
||||
return true;
|
||||
}
|
||||
|
||||
private void updateRedstoneStatus(World world, int x, int y, int z) {
|
||||
TileEntity tile = world.getTileEntity(x, y, z);
|
||||
if (tile != null) {
|
||||
if (tile instanceof TileDislocatorInhibitor te) {
|
||||
if (!player.isSneaking()) te.increaseRange();
|
||||
else te.decreaseRange();
|
||||
|
||||
if (world.isRemote) player.addChatMessage(new ChatComponentText("Range: " + te.getRange()));
|
||||
if (te.isRedstoneActive() ^ world.isBlockIndirectlyGettingPowered(x, y, z)) {
|
||||
te.setRedstoneActive(world.isBlockIndirectlyGettingPowered(x, y, z));
|
||||
world.markBlockForUpdate(x, y, z);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNeighborBlockChange(World world, int x, int y, int z, Block neighbor) {
|
||||
updateRedstoneStatus(world, x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float prx,
|
||||
float pry, float prz) {
|
||||
|
||||
if (!world.isRemote) {
|
||||
FMLNetworkHandler
|
||||
.openGui(player, DraconicEvolution.instance, GuiHandler.GUIID_DISLOCATOR_INHIBITOR, world, x, y, z);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPostBlockPlaced(World world, int x, int y, int z, int meta) {
|
||||
updateRedstoneStatus(world, x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void breakBlock(World worldIn, int x, int y, int z, Block blockBroken, int meta) {
|
||||
TileEntity tile = worldIn.getTileEntity(x, y, z);
|
||||
@@ -81,4 +111,18 @@ public class DislocatorInhibitor extends BlockDE implements ITileEntityProvider
|
||||
public void registerBlockIcons(IIconRegister iconRegister) {
|
||||
blockIcon = iconRegister.registerIcon(References.RESOURCESPREFIX + "inhibitor_block");
|
||||
}
|
||||
|
||||
public static class InfusedObsidianItemBlock extends ItemBlock {
|
||||
|
||||
public InfusedObsidianItemBlock(Block p_i45328_1_) {
|
||||
super(p_i45328_1_);
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public void addInformation(ItemStack p_77624_1_, EntityPlayer p_77624_2_, List list, boolean p_77624_4_) {
|
||||
list.add(EnumChatFormatting.GRAY + StatCollector.translateToLocal("info.de.dislocatorInhibitor.txt"));
|
||||
super.addInformation(p_77624_1_, p_77624_2_, list, p_77624_4_);
|
||||
}
|
||||
}
|
||||
}
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
package com.brandon3055.draconicevolution.common.container;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import com.brandon3055.draconicevolution.common.inventory.SlotFakeItem;
|
||||
import com.brandon3055.draconicevolution.common.tileentities.TileDislocatorInhibitor;
|
||||
|
||||
public class ContainerDislocatorInhibitor extends Container {
|
||||
|
||||
private TileDislocatorInhibitor inhibitor;
|
||||
|
||||
public ContainerDislocatorInhibitor(InventoryPlayer playerInventory, TileDislocatorInhibitor inhibitor) {
|
||||
this.inhibitor = inhibitor;
|
||||
|
||||
bindPlayerInventory(playerInventory);
|
||||
addContainerSlots(inhibitor);
|
||||
}
|
||||
|
||||
private void bindPlayerInventory(InventoryPlayer invPlayer) {
|
||||
for (int x = 0; x < 9; x++) {
|
||||
addSlotToContainer(new Slot(invPlayer, x, 8 + 18 * x, 118));
|
||||
}
|
||||
|
||||
for (int y = 0; y < 3; y++) {
|
||||
for (int x = 0; x < 9; x++) {
|
||||
addSlotToContainer(new Slot(invPlayer, x + y * 9 + 9, 8 + 18 * x, 60 + y * 18));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void addContainerSlots(TileDislocatorInhibitor tileInhibitor) {
|
||||
for (int i = 0; i < 8; i++) {
|
||||
addSlotToContainer(new SlotFakeItem(tileInhibitor, i, 8 + 18 * i, 34));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInteractWith(EntityPlayer player) {
|
||||
return inhibitor.isUseableByPlayer(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canDragIntoSlot(Slot p_94531_1_) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack transferStackInSlot(EntityPlayer player, int slot) {
|
||||
this.inhibitor.addItemFilter(player.inventory.getStackInSlot(slot));
|
||||
return null;
|
||||
}
|
||||
|
||||
public TileDislocatorInhibitor getTileEntity() {
|
||||
return inhibitor;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package com.brandon3055.draconicevolution.common.inventory;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public class SlotFakeItem extends Slot {
|
||||
|
||||
public SlotFakeItem(IInventory inventory, int id, int x, int y) {
|
||||
super(inventory, id, x, y);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPickupFromSlot(EntityPlayer p_82870_1_, ItemStack p_82870_2_) {
|
||||
super.onPickupFromSlot(p_82870_1_, p_82870_2_);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValid(ItemStack stack) {
|
||||
// this is here so NEI CheatItemHandler does not eat the handleDragNDrop event
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSlotStackLimit() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
public boolean isOverSlot(int mouseX, int mouseY) {
|
||||
if (xDisplayPosition < mouseX && mouseX <= xDisplayPosition + 18) {
|
||||
return yDisplayPosition < mouseY && mouseY <= yDisplayPosition + 18;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -115,7 +115,7 @@ public class Magnet extends ItemDE implements IBauble, IConfigurableItem {
|
||||
|
||||
for (EntityItem item : items) {
|
||||
if (item.getEntityItem() == null || ModHelper.isAE2EntityFloatingItem(item)
|
||||
|| TileDislocatorInhibitor.isInInhibitorRange(world, item.posX, item.posY, item.posZ)) {
|
||||
|| TileDislocatorInhibitor.isBlockedByInhibitor(world, item)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
package com.brandon3055.draconicevolution.common.network;
|
||||
|
||||
import com.brandon3055.draconicevolution.common.container.ContainerDislocatorInhibitor;
|
||||
import com.brandon3055.draconicevolution.common.tileentities.TileDislocatorInhibitor;
|
||||
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
public class DislocatorInhibitorButtonPacket implements IMessage {
|
||||
|
||||
private short index = 0;
|
||||
private short value = 0;
|
||||
|
||||
public DislocatorInhibitorButtonPacket() {}
|
||||
|
||||
public DislocatorInhibitorButtonPacket(byte index, short value) {
|
||||
this.index = index;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf bytes) {
|
||||
bytes.writeByte(index);
|
||||
bytes.writeByte(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf bytes) {
|
||||
index = bytes.readByte();
|
||||
value = bytes.readByte();
|
||||
}
|
||||
|
||||
public static class Handler implements IMessageHandler<DislocatorInhibitorButtonPacket, IMessage> {
|
||||
|
||||
@Override
|
||||
public IMessage onMessage(DislocatorInhibitorButtonPacket message, MessageContext ctx) {
|
||||
if (!(ctx
|
||||
.getServerHandler().playerEntity.openContainer instanceof ContainerDislocatorInhibitor container)) {
|
||||
return null;
|
||||
}
|
||||
TileDislocatorInhibitor tile = container.getTileEntity();
|
||||
if (tile == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
switch (message.index) {
|
||||
case 0 -> tile.setRange(message.value);
|
||||
case 1 -> tile.setActivityControl(message.value);
|
||||
case 2 -> tile.setWhitelist(message.value);
|
||||
}
|
||||
ctx.getServerHandler().playerEntity.worldObj.markBlockForUpdate(tile.xCoord, tile.yCoord, tile.zCoord);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
+56
@@ -0,0 +1,56 @@
|
||||
package com.brandon3055.draconicevolution.common.network;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import com.brandon3055.draconicevolution.common.container.ContainerDislocatorInhibitor;
|
||||
import com.brandon3055.draconicevolution.common.tileentities.TileDislocatorInhibitor;
|
||||
|
||||
import cpw.mods.fml.common.network.ByteBufUtils;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
public class SlotFakeClickPacket implements IMessage {
|
||||
|
||||
private short slotIndex = 0;
|
||||
private ItemStack stack;
|
||||
|
||||
public SlotFakeClickPacket() {}
|
||||
|
||||
public SlotFakeClickPacket(byte slotIndex, ItemStack stack) {
|
||||
this.slotIndex = slotIndex;
|
||||
this.stack = stack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf bytes) {
|
||||
bytes.writeByte(slotIndex);
|
||||
ByteBufUtils.writeItemStack(bytes, stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf bytes) {
|
||||
slotIndex = bytes.readByte();
|
||||
stack = ByteBufUtils.readItemStack(bytes);
|
||||
}
|
||||
|
||||
public static class Handler implements IMessageHandler<SlotFakeClickPacket, IMessage> {
|
||||
|
||||
@Override
|
||||
public IMessage onMessage(SlotFakeClickPacket message, MessageContext ctx) {
|
||||
if (!(ctx
|
||||
.getServerHandler().playerEntity.openContainer instanceof ContainerDislocatorInhibitor container)) {
|
||||
return null;
|
||||
}
|
||||
TileDislocatorInhibitor tile = container.getTileEntity();
|
||||
if (tile == null) {
|
||||
return null;
|
||||
}
|
||||
tile.setFilterItem(message.slotIndex, message.stack);
|
||||
|
||||
ctx.getServerHandler().playerEntity.worldObj.markBlockForUpdate(tile.xCoord, tile.yCoord, tile.zCoord);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
+220
-9
@@ -3,6 +3,13 @@ package com.brandon3055.draconicevolution.common.tileentities;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTBase;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.network.NetworkManager;
|
||||
import net.minecraft.network.Packet;
|
||||
@@ -10,22 +17,36 @@ import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class TileDislocatorInhibitor extends TileEntity {
|
||||
import com.brandon3055.draconicevolution.common.container.ContainerDislocatorInhibitor;
|
||||
|
||||
public class TileDislocatorInhibitor extends TileEntity implements IInventory {
|
||||
|
||||
public static final int MAXIMUM_RANGE = 16;
|
||||
public static final int MINIMUM_RANGE = 1;
|
||||
public static final int FILTER_SLOTS = 8;
|
||||
public static final HashMap<World, HashSet<TileDislocatorInhibitor>> inhibitors = new HashMap<>();
|
||||
|
||||
private boolean redstoneActive = false;
|
||||
private ActivityControlType activityControlType = ActivityControlType.ALWAYS_ACTIVE;
|
||||
private boolean registered = false;
|
||||
private int range = 5;
|
||||
|
||||
public static boolean isInInhibitorRange(World world, double x, double y, double z) {
|
||||
private boolean whitelist = false;
|
||||
private final ItemStack[] filter = new ItemStack[FILTER_SLOTS];
|
||||
|
||||
public static boolean isBlockedByInhibitor(World world, EntityItem item) {
|
||||
HashSet<TileDislocatorInhibitor> list = inhibitors.get(world);
|
||||
if (list == null) {
|
||||
return false;
|
||||
}
|
||||
for (TileDislocatorInhibitor inhibitor : list) {
|
||||
if (inhibitor.isInRange(x, y, z)) {
|
||||
if (!inhibitor.shouldBeActive()) {
|
||||
continue;
|
||||
}
|
||||
if (!inhibitor.isBlockingItem(item.getEntityItem())) {
|
||||
continue;
|
||||
}
|
||||
if (inhibitor.isInRange(item.posX, item.posY, item.posZ)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -65,15 +86,37 @@ public class TileDislocatorInhibitor extends TileEntity {
|
||||
this.range = value;
|
||||
}
|
||||
|
||||
public void increaseRange() {
|
||||
if (range < MAXIMUM_RANGE) {
|
||||
range++;
|
||||
public boolean isBlockingItem(ItemStack item) {
|
||||
boolean blocked = false;
|
||||
for (ItemStack itemStack : filter) {
|
||||
if (itemStack == null) {
|
||||
continue;
|
||||
}
|
||||
if (itemStack.getItem() == item.getItem()) {
|
||||
blocked = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (whitelist) {
|
||||
return blocked;
|
||||
}
|
||||
return !blocked;
|
||||
}
|
||||
|
||||
public void decreaseRange() {
|
||||
if (range > MINIMUM_RANGE) {
|
||||
range--;
|
||||
public boolean shouldBeActive() {
|
||||
switch (activityControlType) {
|
||||
case NEVER_ACTIVE -> {
|
||||
return false;
|
||||
}
|
||||
case WITH_REDSTONE -> {
|
||||
return redstoneActive;
|
||||
}
|
||||
case WITHOUT_REDSTONE -> {
|
||||
return !redstoneActive;
|
||||
}
|
||||
default -> {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,6 +128,130 @@ public class TileDislocatorInhibitor extends TileEntity {
|
||||
&& z <= this.zCoord + range + 1;
|
||||
}
|
||||
|
||||
public void setActivityControl(int index) {
|
||||
if (index < 0 || index >= ActivityControlType.values().length) {
|
||||
return;
|
||||
}
|
||||
this.activityControlType = ActivityControlType.values()[index];
|
||||
}
|
||||
|
||||
public ActivityControlType getActivityControlType() {
|
||||
return activityControlType;
|
||||
}
|
||||
|
||||
public boolean isRedstoneActive() {
|
||||
return redstoneActive;
|
||||
}
|
||||
|
||||
public void setRedstoneActive(boolean redstoneActive) {
|
||||
this.redstoneActive = redstoneActive;
|
||||
}
|
||||
|
||||
public void setFilterItem(int slot, ItemStack item) {
|
||||
if (slot < 0 || slot >= FILTER_SLOTS) {
|
||||
return;
|
||||
}
|
||||
setInventorySlotContents(slot, item);
|
||||
}
|
||||
|
||||
public void addItemFilter(ItemStack itemStack) {
|
||||
if (itemStack == null) {
|
||||
return;
|
||||
}
|
||||
for (int i = 0; i < FILTER_SLOTS; i++) {
|
||||
if (filter[i] == null) {
|
||||
setInventorySlotContents(i, itemStack);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isWhitelist() {
|
||||
return whitelist;
|
||||
}
|
||||
|
||||
public void setWhitelist(short value) {
|
||||
this.whitelist = value == 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInventoryName() {
|
||||
return "Dislocator Inhibitor";
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSizeInventory() {
|
||||
return FILTER_SLOTS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlot(int slotIn) {
|
||||
if (slotIn < 0 || slotIn >= FILTER_SLOTS) {
|
||||
return null;
|
||||
}
|
||||
return this.filter[slotIn];
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack decrStackSize(int index, int count) {
|
||||
ItemStack item = this.filter[index];
|
||||
this.filter[index] = null;
|
||||
if (item == null) {
|
||||
return null;
|
||||
}
|
||||
item.stackSize = 0;
|
||||
return item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlotOnClosing(int index) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInventorySlotContents(int index, ItemStack stack) {
|
||||
if (stack != null) {
|
||||
this.filter[index] = stack.copy();
|
||||
this.filter[index].stackSize = 0;
|
||||
} else {
|
||||
this.filter[index] = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUseableByPlayer(EntityPlayer player) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openInventory() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeInventory() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot(int index, ItemStack stack) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCustomInventoryName() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInventoryStackLimit() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
public Container getGuiContainer(InventoryPlayer playerInventory) {
|
||||
return new ContainerDislocatorInhibitor(playerInventory, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Packet getDescriptionPacket() {
|
||||
NBTTagCompound tagCompound = new NBTTagCompound();
|
||||
@@ -101,12 +268,56 @@ public class TileDislocatorInhibitor extends TileEntity {
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound compound) {
|
||||
compound.setInteger("Range", range);
|
||||
compound.setBoolean("RedstoneAcitve", redstoneActive);
|
||||
compound.setString("ActivityControl", activityControlType.name());
|
||||
compound.setBoolean("Whitelist", whitelist);
|
||||
|
||||
int i = 0;
|
||||
for (ItemStack item : filter) {
|
||||
NBTTagCompound itemTag = new NBTTagCompound();
|
||||
if (item != null) {
|
||||
item.writeToNBT(itemTag);
|
||||
compound.setTag("Item" + i, itemTag);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
super.writeToNBT(compound);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound compound) {
|
||||
range = compound.getInteger("Range");
|
||||
redstoneActive = compound.getBoolean("RedstoneAcitve");
|
||||
activityControlType = ActivityControlType.valueOf(compound.getString("ActivityControl"));
|
||||
whitelist = compound.getBoolean("Whitelist");
|
||||
|
||||
for (int i = 0; i < FILTER_SLOTS; i++) {
|
||||
NBTBase tag = compound.getTag("Item" + i);
|
||||
if (tag instanceof NBTTagCompound) {
|
||||
filter[i] = ItemStack.loadItemStackFromNBT((NBTTagCompound) tag);
|
||||
} else {
|
||||
filter[i] = null;
|
||||
}
|
||||
}
|
||||
super.readFromNBT(compound);
|
||||
}
|
||||
|
||||
public enum ActivityControlType {
|
||||
|
||||
ALWAYS_ACTIVE,
|
||||
WITH_REDSTONE,
|
||||
WITHOUT_REDSTONE,
|
||||
NEVER_ACTIVE;
|
||||
|
||||
public ActivityControlType getNext() {
|
||||
return switch (this) {
|
||||
case ALWAYS_ACTIVE -> ActivityControlType.WITH_REDSTONE;
|
||||
case WITH_REDSTONE -> ActivityControlType.WITHOUT_REDSTONE;
|
||||
case WITHOUT_REDSTONE -> ActivityControlType.NEVER_ACTIVE;
|
||||
default -> ActivityControlType.ALWAYS_ACTIVE;
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -297,6 +297,8 @@ info.de.manual.nav1.txt=Navigation Tips
|
||||
info.de.manual.nav2.txt=Press Backspace to go to the previous page.
|
||||
info.de.manual.nav3.txt=Hold shift to scroll faster.
|
||||
|
||||
info.de.dislocatorInhibitor.txt=Magnet blocker
|
||||
|
||||
//Energy Net
|
||||
info.de.modeIn.txt=Mode: Input
|
||||
info.de.modeOut.txt=Mode: Output
|
||||
@@ -661,6 +663,16 @@ gui.de.ShieldRecovery.txt=Shield Recovery
|
||||
gui.de.MoveSpeed.txt=Move Speed
|
||||
gui.de.JumpBoost.txt=Jump Boost
|
||||
|
||||
gui.de.dislocatorInhibitor.range.txt=Range:
|
||||
gui.de.dislocatorInhibitor.tooltip.range.increase.txt=Increase Range
|
||||
gui.de.dislocatorInhibitor.tooltip.range.decrease.txt=Decrease Range
|
||||
gui.de.dislocatorInhibitor.tooltip.activity.always.txt=Active regardles of redstone power
|
||||
gui.de.dislocatorInhibitor.tooltip.activity.with.txt=Active with redstone power
|
||||
gui.de.dislocatorInhibitor.tooltip.activity.without.txt=Active without redstone power
|
||||
gui.de.dislocatorInhibitor.tooltip.activity.never.txt=Always inactive
|
||||
gui.de.dislocatorInhibitor.tooltip.activity.cycle.txt=Click to cycle through activity control
|
||||
gui.de.dislocatorInhibitor.tooltip.whitelist.txt=Only items in filter will be blocked
|
||||
gui.de.dislocatorInhibitor.tooltip.blacklist.txt=Items in filter will NOT be blocked
|
||||
|
||||
//Potions ----------------------------------------------------------------------------------------------------------------------------------------
|
||||
potion.de.effect.txt=Effect
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 2.3 KiB |
Reference in new issue
Block a user