forked from AE2-UEL/AE2FluidCraft-Rework
-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'asdflj/bookmark' into dev
- Loading branch information
Showing
14 changed files
with
522 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
src/main/java/com/glodblock/github/client/gui/GuiFluidAutoFiller.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.glodblock.github.client.gui; | ||
|
||
import appeng.client.gui.AEBaseMEGui; | ||
import appeng.core.localization.GuiText; | ||
import com.glodblock.github.FluidCraft; | ||
import com.glodblock.github.client.gui.container.ContainerFluidAutoFiller; | ||
import com.glodblock.github.common.tile.TileFluidAutoFiller; | ||
import com.glodblock.github.util.NameConst; | ||
import net.minecraft.client.resources.I18n; | ||
import net.minecraft.entity.player.EntityPlayer; | ||
import net.minecraft.entity.player.InventoryPlayer; | ||
import net.minecraft.util.ResourceLocation; | ||
|
||
public class GuiFluidAutoFiller extends AEBaseMEGui { | ||
protected EntityPlayer player; | ||
private static final ResourceLocation TEX_BG = FluidCraft.resource("textures/gui/fluid_auto_filler.png"); | ||
|
||
public GuiFluidAutoFiller(InventoryPlayer ipl, TileFluidAutoFiller tile) { | ||
super(new ContainerFluidAutoFiller(ipl, tile)); | ||
this.player = ipl.player; | ||
} | ||
|
||
@Override | ||
public void drawBG(int offsetX, int offsetY, int mouseX, int mouseY) { | ||
mc.getTextureManager().bindTexture(TEX_BG); | ||
drawTexturedModalRect(offsetX, offsetY, 0, 0, 176, ySize); | ||
} | ||
|
||
@Override | ||
public void drawFG(int offsetX, int offsetY, int mouseX, int mouseY) { | ||
fontRendererObj.drawString(getGuiDisplayName(I18n.format(NameConst.GUI_FLUID_AUTO_FILLER)), 8, 6, 0x404040); | ||
fontRendererObj.drawString(GuiText.inventory.getLocal(), 8, ySize - 94, 0x404040); | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
src/main/java/com/glodblock/github/client/gui/container/ContainerFluidAutoFiller.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package com.glodblock.github.client.gui.container; | ||
|
||
import appeng.container.AEBaseContainer; | ||
import appeng.container.slot.SlotFake; | ||
import com.glodblock.github.common.tile.TileFluidAutoFiller; | ||
import com.glodblock.github.util.Util; | ||
import net.minecraft.entity.player.InventoryPlayer; | ||
import net.minecraft.inventory.IInventory; | ||
import net.minecraft.item.ItemStack; | ||
import org.apache.commons.lang3.tuple.MutablePair; | ||
|
||
public class ContainerFluidAutoFiller extends AEBaseContainer { | ||
public static class FakeSlot extends SlotFake { | ||
public FakeSlot(IInventory inv, int idx, int x, int y) { | ||
super(inv, idx, x, y); | ||
} | ||
|
||
@Override | ||
public void putStack(ItemStack is) { | ||
MutablePair<Boolean, ItemStack> result = ContainerFluidAutoFiller.isItemValid(is); | ||
if (result.left) { | ||
if (super.getHasStack()) super.clearStack(); | ||
super.putStack(result.right); | ||
} | ||
} | ||
} | ||
|
||
private final TileFluidAutoFiller tile; | ||
|
||
public ContainerFluidAutoFiller(InventoryPlayer ipl, TileFluidAutoFiller tile) { | ||
super(ipl, tile); | ||
this.tile = tile; | ||
addSlotToContainer(new FakeSlot(tile.getInventory(), 0, 80, 35)); | ||
bindPlayerInventory(ipl, 0, 84); | ||
} | ||
|
||
public static MutablePair<Boolean, ItemStack> isItemValid(ItemStack itemStack) { | ||
boolean result = Util.FluidUtil.isFluidContainer(itemStack); | ||
if (!result) return new MutablePair<>(false, null); | ||
ItemStack tank = itemStack.copy(); | ||
tank.stackSize = 1; | ||
if (Util.FluidUtil.isFilled(tank)) { | ||
return new MutablePair<>(true, Util.FluidUtil.clearFluid(tank)); | ||
} else { | ||
return new MutablePair<>(true, tank); | ||
} | ||
} | ||
|
||
@Override | ||
public void detectAndSendChanges() { | ||
super.detectAndSendChanges(); | ||
tile.updatePattern(); | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
src/main/java/com/glodblock/github/common/block/BlockFluidAutoFiller.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package com.glodblock.github.common.block; | ||
|
||
import appeng.api.config.SecurityPermissions; | ||
import appeng.util.Platform; | ||
import com.glodblock.github.common.item.FCBaseItemBlock; | ||
import com.glodblock.github.common.tabs.FluidCraftingTabs; | ||
import com.glodblock.github.common.tile.TileFluidAutoFiller; | ||
import com.glodblock.github.inventory.InventoryHandler; | ||
import com.glodblock.github.inventory.gui.GuiType; | ||
import com.glodblock.github.util.BlockPos; | ||
import com.glodblock.github.util.NameConst; | ||
import com.glodblock.github.util.Util; | ||
import cpw.mods.fml.common.registry.GameRegistry; | ||
import net.minecraft.block.material.Material; | ||
import net.minecraft.entity.player.EntityPlayer; | ||
import net.minecraft.util.ChatComponentText; | ||
import net.minecraft.world.World; | ||
import net.minecraftforge.common.util.ForgeDirection; | ||
|
||
public class BlockFluidAutoFiller extends FCBaseBlock { | ||
|
||
public BlockFluidAutoFiller() { | ||
super(Material.iron, NameConst.BLOCK_FLUID_AUTO_FILLER); | ||
setTileEntity(TileFluidAutoFiller.class); | ||
setFullBlock(false); | ||
setOpaque(false); | ||
this.lightOpacity = 3; | ||
} | ||
|
||
@Override | ||
public BlockFluidAutoFiller register() { | ||
GameRegistry.registerBlock(this, FCBaseItemBlock.class, NameConst.BLOCK_FLUID_AUTO_FILLER); | ||
GameRegistry.registerTileEntity(TileFluidAutoFiller.class, NameConst.BLOCK_FLUID_AUTO_FILLER); | ||
setCreativeTab(FluidCraftingTabs.INSTANCE); | ||
return this; | ||
} | ||
|
||
@Override | ||
public boolean onActivated( | ||
World world, int x, int y, int z, EntityPlayer player, int facing, float hitX, float hitY, float hitZ) { | ||
if (player.isSneaking()) { | ||
return false; | ||
} | ||
TileFluidAutoFiller tile = getTileEntity(world, x, y, z); | ||
if (tile != null) { | ||
if (Platform.isServer()) { | ||
if (Util.hasPermission(player, SecurityPermissions.INJECT, tile)) { | ||
InventoryHandler.openGui( | ||
player, | ||
world, | ||
new BlockPos(x, y, z), | ||
ForgeDirection.getOrientation(facing), | ||
GuiType.FLUID_AUTO_FILLER); | ||
} else { | ||
player.addChatComponentMessage(new ChatComponentText("You don't have permission to view.")); | ||
} | ||
} | ||
return true; | ||
} | ||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.