Compare commits

...
Author SHA1 Message Date
Martin Robertz f0ee6d1435 update 2025-05-23 23:51:11 +02:00
Martin Robertz 55c4148f75 Merge remote-tracking branch 'Shadow1590/inhibitorImprovements' into dev 2025-05-23 23:50:45 +02:00
Martin Robertz 36badb5833 Merge remote-tracking branch 'origin/mp-magnet' into dev 2025-05-23 23:50:40 +02:00
Shadow1590 8295097eb4 button hovered change and fix 2025-05-19 12:40:02 +02:00
Ruling-0 33e048a295 Move player drop check to server-only 2025-05-19 00:21:05 -05:00
Ruling-0 358c55b82d Magnet attracts only if closest player, and delay self-drop 2025-05-19 00:12:31 -05:00
Shadow1590 4e0dd64054 spotless 2025-05-14 17:50:29 +02:00
Shadow1590 6894348c7f Displaying inventory name :) 2025-05-14 17:49:47 +02:00
Shadow1590 b11a4aa05f Localization 2025-05-14 17:20:26 +02:00
Shadow1590 0d8c036943 Review fixes 2025-05-14 17:14:16 +02:00
Martin Robertz aa49ba56ac Merge remote-tracking branch 'Shadow1590/inhibitorImprovements' into dev 2025-05-12 09:24:45 +02:00
Maya 426837a212 Merge branch 'master' into inhibitorImprovements 2025-04-09 00:26:48 -05:00
Shadow1590 dd3366bdc3 NEI drag and drop handling 2025-03-14 00:19:10 +01:00
Shadow1590 c437a2a440 Spotless 2025-03-13 20:26:00 +01:00
Shadow1590 ca32c00962 Gui upgrades plus translations 2025-03-13 20:24:06 +01:00
Shadow1590 e82e89b7ba Added gui, activity control and filter 2025-03-12 23:38:11 +01:00
13 changed files with 788 additions and 33 deletions

No files matched your search

+5 -5
View File
@@ -4,13 +4,13 @@ dependencies {
api("com.github.GTNewHorizons:BrandonsCore:1.2.0-GTNH:dev")
api("curse.maven:cofh-lib-220333:2388748")
compileOnly("com.github.GTNewHorizons:ForestryMC:4.10.7:api") {transitive = false}
compileOnly("com.github.GTNewHorizons:OpenComputers:1.11.13-GTNH:api") {transitive = false}
compileOnly("com.github.GTNewHorizons:NotEnoughItems:2.7.40-GTNH:dev") {transitive = false}
compileOnly("com.github.GTNewHorizons:ForestryMC:4.10.8:api") {transitive = false}
compileOnly("com.github.GTNewHorizons:OpenComputers:1.11.15-GTNH:api") {transitive = false}
compileOnly("com.github.GTNewHorizons:NotEnoughItems:2.7.45-GTNH:dev") {transitive = false}
compileOnly("com.github.GTNewHorizons:CodeChickenLib:1.3.0:dev") {transitive = false}
compileOnly("com.github.GTNewHorizons:inventory-tweaks:1.7.1:dev") {transitive = false}
compileOnly('com.github.GTNewHorizons:Baubles-Expanded:2.1.7-GTNH:dev') {transitive = false}
compileOnly("com.github.GTNewHorizons:GT5-Unofficial:5.09.51.282:dev") {transitive = false}
compileOnly('com.github.GTNewHorizons:Baubles-Expanded:2.1.8-GTNH:dev') {transitive = false}
compileOnly("com.github.GTNewHorizons:GT5-Unofficial:5.09.51.291:dev") {transitive = false}
compileOnly("thaumcraft:Thaumcraft:1.7.10-4.2.3.5:dev") {transitive = false}
compileOnly("curse.maven:computercraft-67504:2269339") {transitive = false}
@@ -0,0 +1,239 @@
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 = 150;
syncWithServer();
}
@Override
@SuppressWarnings("unchecked")
public void initGui() {
super.initGui();
buttonList.clear();
buttonList.add(new GuiButtonAHeight(0, guiLeft + 7, guiTop + 19, 18, 18, "-"));
buttonList.add(new GuiButtonAHeight(1, guiLeft + 97, guiTop + 19, 18, 18, "+"));
buttonList.add(new GuiButtonAHeight(2, guiLeft + 151, guiTop + 19, 18, 18, ""));
buttonList.add(new GuiButtonAHeight(3, guiLeft + 151, guiTop + 41, 18, 18, ""));
}
@Override
protected void drawGuiContainerForegroundLayer(int x, int y) {
fontRendererObj.drawString(
StatCollector.translateToLocal("tile.draconicevolution:dislocatorInhibitor.name"),
7,
5,
0x222222);
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 (isButtonHovered(x, y, 7, 19, 18, 18)) {
lines.add(StatCollector.translateToLocal("gui.de.dislocatorInhibitor.tooltip.range.decrease.txt"));
} else if (isButtonHovered(x, y, 97, 19, 18, 18)) {
lines.add(StatCollector.translateToLocal("gui.de.dislocatorInhibitor.tooltip.range.increase.txt"));
} else if (isButtonHovered(x, y, 151, 19, 18, 18)) {
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 (isButtonHovered(x, y, 151, 41, 18, 18)) {
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);
}
}
private boolean isButtonHovered(int mouseX, int mouseY, int buttonX, int buttonY, int width, int height) {
return (mouseX >= buttonX + guiLeft && mouseX < buttonX + width + guiLeft)
&& (mouseY >= buttonY + guiTop && mouseY < buttonY + height + guiTop);
}
@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,
25,
0x000000,
false);
fontRendererObj.drawString(String.valueOf(range), range < 10 ? 78 : 75, 25, 0x000000, false);
}
private void drawButtonIcons() {
GL11.glColor4f(1, 1, 1, 1);
Minecraft.getMinecraft().getTextureManager().bindTexture(texture);
// activity control button
drawTexturedModalRect(151, 19, 0, 150 + (18 * activityControlType.ordinal()), 18, 18);
// whitelist button
drawTexturedModalRect(151, 41, 18, 150 + (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, 41, 36, 150, 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() {
@@ -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, DislocatorInhibitorItemBlock.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 DislocatorInhibitorItemBlock extends ItemBlock {
public DislocatorInhibitorItemBlock(Block block) {
super(block);
}
@SideOnly(Side.CLIENT)
@Override
public void addInformation(ItemStack item, EntityPlayer player, List lines, boolean advanced) {
lines.add(EnumChatFormatting.GRAY + StatCollector.translateToLocal("info.de.dislocatorInhibitor.txt"));
super.addInformation(item, player, lines, advanced);
}
}
}
@@ -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, 126));
}
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, 68 + y * 18));
}
}
}
public void addContainerSlots(TileDislocatorInhibitor tileInhibitor) {
for (int i = 0; i < 8; i++) {
addSlotToContainer(new SlotFakeItem(tileInhibitor, i, 8 + 18 * i, 42));
}
}
@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,31 @@
package com.brandon3055.draconicevolution.common.inventory;
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 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;
}
}
@@ -112,10 +112,12 @@ public class Magnet extends ItemDE implements IBauble, IConfigurableItem {
entity.posZ).expand(range, range, range));
boolean playSound = false;
boolean didPlayerDrop;
NBTTagCompound itemNBT = new NBTTagCompound();
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;
}
@@ -126,19 +128,36 @@ public class Magnet extends ItemDE implements IBauble, IConfigurableItem {
== item.getEntityItem().getItemDamage())) {
continue;
}
playSound = true;
if (item.delayBeforeCanPickup > 0) {
item.delayBeforeCanPickup = 0;
EntityPlayer closestPlayer = world.getClosestPlayerToEntity(item, range);
if (closestPlayer != null && closestPlayer != player) {
continue;
}
item.writeEntityToNBT(itemNBT);
if (!world.isRemote) {
didPlayerDrop = item.func_145800_j() != null
&& item.func_145800_j().equals(player.getCommandSenderName());
if (!didPlayerDrop) item.delayBeforeCanPickup = 0;
if (item.delayBeforeCanPickup <= 0) {
itemNBT.setBoolean("attractable", true);
item.readEntityFromNBT(itemNBT);
}
}
if (itemNBT.getBoolean("attractable")) {
playSound = true;
item.motionX = 0;
item.motionY = 0;
item.motionZ = 0;
item.setPosition(
entity.posX - 0.2 + (world.rand.nextDouble() * 0.4),
entity.posY - 0.6,
entity.posZ - 0.2 + (world.rand.nextDouble() * 0.4));
}
item.motionX = 0;
item.motionY = 0;
item.motionZ = 0;
item.setPosition(
entity.posX - 0.2 + (world.rand.nextDouble() * 0.4),
entity.posY - 0.6,
entity.posZ - 0.2 + (world.rand.nextDouble() * 0.4));
}
if (playSound && !ConfigHandler.itemDislocatorDisableSound) {
world.playSoundAtEntity(
entity,
@@ -0,0 +1,56 @@
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 == 1);
}
return null;
}
}
}
@@ -0,0 +1,54 @@
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);
return null;
}
}
}
@@ -3,29 +3,52 @@ 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;
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.StatCollector;
import net.minecraft.world.World;
public class TileDislocatorInhibitor extends TileEntity {
import com.brandon3055.draconicevolution.common.ModBlocks;
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;
}
}
@@ -63,17 +86,40 @@ public class TileDislocatorInhibitor extends TileEntity {
value = MAXIMUM_RANGE;
}
this.range = value;
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
}
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 +131,134 @@ 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];
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
}
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);
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
}
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(boolean value) {
this.whitelist = value;
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
}
@Override
public String getInventoryName() {
return StatCollector.translateToLocal(ModBlocks.dislocatorInhibitor.getUnlocalizedName() + ".name");
}
@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 +275,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=Always Active
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 demagnetized
gui.de.dislocatorInhibitor.tooltip.blacklist.txt=Items in filter will NOT be demagnetized
//Potions ----------------------------------------------------------------------------------------------------------------------------------------
potion.de.effect.txt=Effect
Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB