diff --git a/src/generated/resources/.cache/cache b/src/generated/resources/.cache/cache index 63e83907..64f2dcbc 100644 --- a/src/generated/resources/.cache/cache +++ b/src/generated/resources/.cache/cache @@ -18,7 +18,7 @@ e1a98bd53fca155e4bbb03c1e548341af0f84bd7 assets/bloodmagic/blockstates/masterrit b03040d7a168653bf8df3600033b8fde2383db30 assets/bloodmagic/blockstates/selfsacrificerune.json 487ffdc02ab7b65aafcb932e3b5cf6ea0500b21d assets/bloodmagic/blockstates/speedrune.json e6d9cf699667aaa47efff37b2b033895dee29c15 assets/bloodmagic/blockstates/waterritualstone.json -775f7c01fb20ba9b55ff5c46d7fef0acd5f591ae assets/bloodmagic/lang/en_us.json +2fd83f690f0a9af248196620b528a4f9717962a1 assets/bloodmagic/lang/en_us.json 34445195b9f2459475cde53454bc8e37d32865d7 assets/bloodmagic/models/block/accelerationrune.json bcdbccc49d4509571be6988762ab87126275a4c8 assets/bloodmagic/models/block/airritualstone.json adf6c0b1e25451609486dc8c8cfbd9cf0f8c67f4 assets/bloodmagic/models/block/alchemicalreactionchamber.json diff --git a/src/generated/resources/assets/bloodmagic/lang/en_us.json b/src/generated/resources/assets/bloodmagic/lang/en_us.json index 7525e488..7647403e 100644 --- a/src/generated/resources/assets/bloodmagic/lang/en_us.json +++ b/src/generated/resources/assets/bloodmagic/lang/en_us.json @@ -24,6 +24,7 @@ "chat.bloodmagic.ritual.notValid": "You feel that these runes are not configured correctly...", "chat.bloodmagic.ritual.prevent": "The ritual is actively resisting you!", "chat.bloodmagic.ritual.weak": "You feel a push, but are too weak to perform this ritual.", + "gui.bloodmagic.empty": "Empty", "item.bloodmagic.activationcrystalawakened": "Awakened Activation Crystal", "item.bloodmagic.activationcrystalcreative": "Creative Activation Crystal", "item.bloodmagic.activationcrystalweak": "Weak Activation Crystal", @@ -114,6 +115,7 @@ "ritual.bloodmagic.waterRitual": "Ritual of the Full Spring", "ritual.bloodmagic.wellOfSufferingRitual": "Well of Suffering", "ritual.bloodmagic.zephyrRitual": "Call of the Zephyr", + "tile.bloodmagic.arc.name": "Alchemical Reaction Chamber", "tile.bloodmagic.soulforge.name": "Hellfire Forge", "tooltip.bloodmagic.activationcrystal.awakened": "Activates more powerful rituals", "tooltip.bloodmagic.activationcrystal.creative": "Creative Only - Activates any ritual", @@ -147,6 +149,7 @@ "tooltip.bloodmagic.diviner.totalRune": "Total Runes: %d", "tooltip.bloodmagic.diviner.waterRune": "Water Runes: %d", "tooltip.bloodmagic.extraInfo": "&9-Hold shift for more info-", + "tooltip.bloodmagic.holdShiftForInfo": "Press shift for extra info", "tooltip.bloodmagic.inscriber.desc": "The writing is on the wall...", "tooltip.bloodmagic.orb.desc": "Stores raw Life Essence", "tooltip.bloodmagic.orb.owner": "Added by: %s", diff --git a/src/main/java/WayofTime/bloodmagic/altar/BloodAltar.java b/src/main/java/WayofTime/bloodmagic/altar/BloodAltar.java index 34b6a77d..a93e82d3 100644 --- a/src/main/java/WayofTime/bloodmagic/altar/BloodAltar.java +++ b/src/main/java/WayofTime/bloodmagic/altar/BloodAltar.java @@ -178,7 +178,6 @@ public class BloodAltar// implements IFluidHandler public void startCycle() { -// System.out.println("Starting Cycle"); if (tileAltar.getWorld() != null) tileAltar.getWorld().notifyBlockUpdate(tileAltar.getPos(), tileAltar.getWorld().getBlockState(tileAltar.getPos()), tileAltar.getWorld().getBlockState(tileAltar.getPos()), 3); @@ -332,7 +331,6 @@ public class BloodAltar// implements IFluidHandler } if (fluid != null && fluid.getAmount() >= 1) { - System.out.println("Draining in order to craft! Progress: " + progress + "/" + liquidRequired); // int liquidDrained = Math.min((int) (altarTier.ordinal() >= 1 // ? consumptionRate * (1 + consumptionMultiplier) // : consumptionRate), fluid.getAmount()); diff --git a/src/main/java/WayofTime/bloodmagic/tile/TileInventory.java b/src/main/java/WayofTime/bloodmagic/tile/TileInventory.java index a737e704..961fc1fd 100644 --- a/src/main/java/WayofTime/bloodmagic/tile/TileInventory.java +++ b/src/main/java/WayofTime/bloodmagic/tile/TileInventory.java @@ -264,11 +264,11 @@ public class TileInventory extends TileBase implements IInventory if (this instanceof ISidedInventory) { handlerDown = LazyOptional.of(() -> new SidedInvWrapper((ISidedInventory) this, Direction.DOWN)); - handlerUp = LazyOptional.of(() -> new SidedInvWrapper((ISidedInventory) this, Direction.DOWN)); - handlerNorth = LazyOptional.of(() -> new SidedInvWrapper((ISidedInventory) this, Direction.DOWN)); - handlerSouth = LazyOptional.of(() -> new SidedInvWrapper((ISidedInventory) this, Direction.DOWN)); - handlerWest = LazyOptional.of(() -> new SidedInvWrapper((ISidedInventory) this, Direction.DOWN)); - handlerEast = LazyOptional.of(() -> new SidedInvWrapper((ISidedInventory) this, Direction.DOWN)); + handlerUp = LazyOptional.of(() -> new SidedInvWrapper((ISidedInventory) this, Direction.UP)); + handlerNorth = LazyOptional.of(() -> new SidedInvWrapper((ISidedInventory) this, Direction.NORTH)); + handlerSouth = LazyOptional.of(() -> new SidedInvWrapper((ISidedInventory) this, Direction.SOUTH)); + handlerWest = LazyOptional.of(() -> new SidedInvWrapper((ISidedInventory) this, Direction.WEST)); + handlerEast = LazyOptional.of(() -> new SidedInvWrapper((ISidedInventory) this, Direction.EAST)); } else { handlerDown = LazyOptional.of(() -> new InvWrapper(this)); diff --git a/src/main/java/wayoftime/bloodmagic/client/screens/ScreenAlchemicalReactionChamber.java b/src/main/java/wayoftime/bloodmagic/client/screens/ScreenAlchemicalReactionChamber.java index cc06b489..26c23ad7 100644 --- a/src/main/java/wayoftime/bloodmagic/client/screens/ScreenAlchemicalReactionChamber.java +++ b/src/main/java/wayoftime/bloodmagic/client/screens/ScreenAlchemicalReactionChamber.java @@ -1,5 +1,8 @@ package wayoftime.bloodmagic.client.screens; +import java.util.ArrayList; +import java.util.List; + import com.mojang.blaze3d.matrix.MatrixStack; import com.mojang.blaze3d.systems.RenderSystem; @@ -7,9 +10,11 @@ import net.minecraft.entity.player.PlayerInventory; import net.minecraft.util.ResourceLocation; import net.minecraft.util.text.ITextComponent; import net.minecraft.util.text.TranslationTextComponent; +import net.minecraftforge.fml.client.gui.GuiUtils; import wayoftime.bloodmagic.BloodMagic; import wayoftime.bloodmagic.tile.TileAlchemicalReactionChamber; import wayoftime.bloodmagic.tile.contailer.ContainerAlchemicalReactionChamber; +import wayoftime.bloodmagic.util.handler.event.ClientHandler; public class ScreenAlchemicalReactionChamber extends ScreenBase { @@ -40,13 +45,21 @@ public class ScreenAlchemicalReactionChamber extends ScreenBase tooltip = new ArrayList<>(); +// FluidTank inputTank = new FluidTank(FluidAttributes.BUCKET_VOLUME * 2); +// inputTank.fill(new FluidStack(Fluids.WATER, 1000), FluidAction.EXECUTE); + + ClientHandler.handleGuiTank(stack, tileARC.inputTank, this.guiLeft + 8, this.guiTop + + 40, 16, 63, 194, 0, 16, 64, mouseX, mouseY, background.toString(), tooltip); + + if (!tooltip.isEmpty()) + GuiUtils.drawHoveringText(stack, tooltip, mouseX, mouseY, width, height, -1, font); + } + // @Override protected void drawGuiContainerForegroundLayer(MatrixStack stack, int mouseX, int mouseY) @@ -65,6 +78,12 @@ public class ScreenAlchemicalReactionChamber extends ScreenBase { + RenderSystem.enableBlend(); + RenderSystem.defaultBlendFunc(); + }, RenderSystem::disableBlend); + protected static final RenderState.TransparencyState NO_TRANSPARENCY = new RenderState.TransparencyState("no_transparency", RenderSystem::disableBlend, () -> { + }); + protected static final RenderState.DepthTestState DEPTH_ALWAYS = new RenderState.DepthTestState("", GL11.GL_ALWAYS); + + static + { + RenderType.State fullbrightSolidState = RenderType.State.getBuilder().shadeModel(SHADE_ENABLED).lightmap(LIGHTMAP_DISABLED).texture(BLOCK_SHEET_MIPPED).build(true); + SOLID_FULLBRIGHT = RenderType.makeType(BloodMagic.MODID + ":block_fullbright", DefaultVertexFormats.BLOCK, GL11.GL_QUADS, 256, fullbrightSolidState); + RenderType.State translucentNoDepthState = RenderType.State.getBuilder().transparency(TRANSLUCENT_TRANSPARENCY).line(new LineState(OptionalDouble.of(2))).texture(new TextureState()).depthTest(DEPTH_ALWAYS).build(false); + RenderType.State translucentNoTextureState = RenderType.State.getBuilder().transparency(TRANSLUCENT_TRANSPARENCY).texture(new TextureState()).build(false); + TRANSLUCENT_LINES = RenderType.makeType(BloodMagic.MODID + ":translucent_lines", DefaultVertexFormats.POSITION_COLOR, GL11.GL_LINES, 256, translucentNoDepthState); + LINES = RenderType.makeType(BloodMagic.MODID + ":lines", DefaultVertexFormats.POSITION_COLOR, GL11.GL_LINES, 256, RenderType.State.getBuilder().build(false)); + TRANSLUCENT_TRIANGLES = RenderType.makeType(BloodMagic.MODID + ":translucent_triangle_fan", DefaultVertexFormats.POSITION_COLOR, GL11.GL_TRIANGLES, 256, translucentNoDepthState); + TRANSLUCENT_POSITION_COLOR = RenderType.makeType(BloodMagic.MODID + ":translucent_pos_color", DefaultVertexFormats.POSITION_COLOR, GL11.GL_QUADS, 256, translucentNoTextureState); + TRANSLUCENT_NO_DEPTH = RenderType.makeType(BloodMagic.MODID + ":translucent_no_depth", DefaultVertexFormats.POSITION_COLOR, GL11.GL_QUADS, 256, translucentNoDepthState); + RenderType.State chunkMarkerState = RenderType.State.getBuilder().texture(new TextureState()).transparency(TRANSLUCENT_TRANSPARENCY).cull(new CullState(false)).shadeModel(new ShadeModelState(true)).line(new LineState(OptionalDouble.of(5))).build(false); + CHUNK_MARKER = RenderType.makeType(BloodMagic.MODID + ":chunk_marker", DefaultVertexFormats.POSITION_COLOR, GL11.GL_LINES, 256, chunkMarkerState); + VEIN_MARKER = RenderType.makeType(BloodMagic.MODID + ":vein_marker", DefaultVertexFormats.POSITION_COLOR, GL11.GL_LINE_LOOP, 256, chunkMarkerState); + POSITION_COLOR_TEX_LIGHTMAP = RenderType.makeType(BloodMagic.MODID + ":pos_color_tex_lightmap", DefaultVertexFormats.POSITION_COLOR_TEX_LIGHTMAP, GL11.GL_QUADS, 256, RenderType.State.getBuilder().texture(new TextureState(PlayerContainer.LOCATION_BLOCKS_TEXTURE, false, false)).lightmap(new LightmapState(true)).build(false)); + POSITION_COLOR_LIGHTMAP = RenderType.makeType(BloodMagic.MODID + ":pos_color_lightmap", DefaultVertexFormats.POSITION_COLOR_LIGHTMAP, GL11.GL_QUADS, 256, RenderType.State.getBuilder().texture(new TextureState()).lightmap(new LightmapState(true)).build(false)); + ITEM_DAMAGE_BAR = RenderType.makeType(BloodMagic.MODID + ":item_damage_bar", DefaultVertexFormats.POSITION_COLOR, GL11.GL_QUADS, 256, RenderType.State.getBuilder().depthTest(DEPTH_ALWAYS).texture(new TextureState()).alpha(new AlphaState(0)).transparency(NO_TRANSPARENCY).build(false)); + } + + public static RenderType getGui(ResourceLocation texture) + { + return RenderType.makeType("gui_" + texture, DefaultVertexFormats.POSITION_COLOR_TEX, GL11.GL_QUADS, 256, RenderType.State.getBuilder().texture(new TextureState(texture, false, false)).alpha(new AlphaState(0.5F)).build(false)); + } + + public static RenderType getLines(float lineWidth) + { + return RenderType.makeType("lines_color_pos_" + lineWidth, DefaultVertexFormats.POSITION_COLOR, GL11.GL_LINES, 256, RenderType.State.getBuilder().line(new LineState(OptionalDouble.of(lineWidth))).texture(new TextureState()).build(false)); + } + + public static RenderType getPoints(float pointSize) + { + // Not really a fog state, but using it like this makes using RenderType.State + // with custom states possible + FogState setPointSize = new FogState(BloodMagic.MODID + ":pointsize_" + pointSize, () -> GL11.glPointSize(pointSize), () -> { + GL11.glPointSize(1); + }); + return RenderType.makeType("point_pos_color_" + pointSize, DefaultVertexFormats.POSITION_COLOR, GL11.GL_POINTS, 256, RenderType.State.getBuilder().fog(setPointSize).texture(new TextureState()).build(false)); + } + + public static RenderType getPositionTex(ResourceLocation texture) + { + return RenderType.makeType(BloodMagic.MODID + ":pos_tex_" + texture, DefaultVertexFormats.POSITION_TEX, GL11.GL_QUADS, 256, RenderType.State.getBuilder().texture(new TextureState(texture, false, false)).build(false)); + } + + public static RenderType getFullbrightTranslucent(ResourceLocation resourceLocation) + { + RenderType.State glState = RenderType.State.getBuilder().transparency(TRANSLUCENT_TRANSPARENCY).texture(new TextureState(resourceLocation, false, false)).lightmap(new LightmapState(false)).build(false); + return RenderType.makeType("BloodMagic:fullbright_translucent_" + resourceLocation, DefaultVertexFormats.BLOCK, GL11.GL_QUADS, 256, glState); + } + + public static IRenderTypeBuffer wrapWithStencil(IRenderTypeBuffer in, Consumer setupStencilArea, String name, int ref) + { + return wrapWithAdditional(in, "stencil_" + name + "_" + ref, () -> { + GL11.glEnable(GL11.GL_STENCIL_TEST); + RenderSystem.colorMask(false, false, false, false); + RenderSystem.depthMask(false); + GL11.glStencilFunc(GL11.GL_NEVER, 1, 0xFF); + GL11.glStencilOp(GL11.GL_REPLACE, GL11.GL_KEEP, GL11.GL_KEEP); + + GL11.glStencilMask(0xFF); + RenderSystem.clear(GL11.GL_STENCIL_BUFFER_BIT, true); + RenderSystem.disableTexture(); + Tessellator tes = Tessellator.getInstance(); + BufferBuilder bb = tes.getBuffer(); + bb.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION); + setupStencilArea.accept(bb); + tes.draw(); + RenderSystem.enableTexture(); + RenderSystem.colorMask(true, true, true, true); + RenderSystem.depthMask(true); + GL11.glStencilMask(0x00); + GL11.glStencilFunc(GL11.GL_EQUAL, ref, 0xFF); + }, () -> GL11.glDisable(GL11.GL_STENCIL_TEST)); + } + + public static IRenderTypeBuffer disableLighting(IRenderTypeBuffer in) + { + return wrapWithAdditional(in, "no_lighting", RenderSystem::disableLighting, () -> { + }); + } + + public static IRenderTypeBuffer disableCull(IRenderTypeBuffer in) + { + return wrapWithAdditional(in, "no_cull", RenderSystem::disableCull, RenderSystem::enableCull); + } + + private static IRenderTypeBuffer wrapWithAdditional(IRenderTypeBuffer in, String name, Runnable setup, Runnable teardown) + { + return type -> { + return in.getBuffer(new RenderType(BloodMagic.MODID + ":" + type + "_" + name, type.getVertexFormat(), type.getDrawMode(), type.getBufferSize(), type.isUseDelegate(), false, () -> { + type.setupRenderState(); + setup.run(); + }, () -> { + teardown.run(); + type.clearRenderState(); + }) + { + }); + }; + } +} diff --git a/src/main/java/wayoftime/bloodmagic/common/data/GeneratorLanguage.java b/src/main/java/wayoftime/bloodmagic/common/data/GeneratorLanguage.java index ca769d38..c08a3baf 100644 --- a/src/main/java/wayoftime/bloodmagic/common/data/GeneratorLanguage.java +++ b/src/main/java/wayoftime/bloodmagic/common/data/GeneratorLanguage.java @@ -23,6 +23,7 @@ public class GeneratorLanguage extends LanguageProvider // Tile Entitites add("tile.bloodmagic.soulforge.name", "Hellfire Forge"); + add("tile.bloodmagic.arc.name", "Alchemical Reaction Chamber"); // Blood Orb tooltips add("tooltip.bloodmagic.extraInfo", "&9-Hold shift for more info-"); @@ -104,6 +105,8 @@ public class GeneratorLanguage extends LanguageProvider add("tooltip.bloodmagic.diviner.extraExtraInfo", "-Hold shift + alt for augmentation info-"); add("tooltip.bloodmagic.diviner.currentDirection", "Current Direction: %s"); + add("tooltip.bloodmagic.holdShiftForInfo", "Press shift for extra info"); + add("ritual.bloodmagic.testRitual", "Test Ritual"); add("ritual.bloodmagic.waterRitual", "Ritual of the Full Spring"); add("ritual.bloodmagic.lavaRitual", "Serenade of the Nether"); @@ -235,5 +238,8 @@ public class GeneratorLanguage extends LanguageProvider add("chat.bloodmagic.ritual.activate", "A rush of energy flows through the ritual!"); add("chat.bloodmagic.ritual.notValid", "You feel that these runes are not configured correctly..."); + // GUI + add("gui.bloodmagic.empty", "Empty"); + } } diff --git a/src/main/java/wayoftime/bloodmagic/common/recipe/BloodAltarRecipeProvider.java b/src/main/java/wayoftime/bloodmagic/common/recipe/BloodAltarRecipeProvider.java index ab71d3f8..6e6e86cf 100644 --- a/src/main/java/wayoftime/bloodmagic/common/recipe/BloodAltarRecipeProvider.java +++ b/src/main/java/wayoftime/bloodmagic/common/recipe/BloodAltarRecipeProvider.java @@ -26,7 +26,7 @@ public class BloodAltarRecipeProvider implements ISubRecipeProvider BloodAltarRecipeBuilder.altar(Ingredient.fromTag(Tags.Items.STONE), new ItemStack(BloodMagicItems.SLATE.get()), AltarTier.ONE.ordinal(), 1000, 5, 5).build(consumer, new ResourceLocation(BloodMagic.MODID, basePath + "slate")); // TWO - BloodAltarRecipeBuilder.altar(Ingredient.fromItems(BloodMagicItems.SLATE.get()), new ItemStack(BloodMagicItems.REINFORCED_SLATE.get()), AltarTier.THREE.ordinal(), 2000, 5, 5).build(consumer, BloodMagic.rl(basePath + "reinforcedslate")); + BloodAltarRecipeBuilder.altar(Ingredient.fromItems(BloodMagicItems.SLATE.get()), new ItemStack(BloodMagicItems.REINFORCED_SLATE.get()), AltarTier.TWO.ordinal(), 2000, 5, 5).build(consumer, BloodMagic.rl(basePath + "reinforcedslate")); BloodAltarRecipeBuilder.altar(Ingredient.fromTag(Tags.Items.STORAGE_BLOCKS_REDSTONE), new ItemStack(BloodMagicItems.APPRENTICE_BLOOD_ORB.get()), AltarTier.TWO.ordinal(), 5000, 5, 5).build(consumer, BloodMagic.rl(basePath + "apprenticebloodorb")); BloodAltarRecipeBuilder.altar(Ingredient.fromItems(Items.IRON_SWORD), new ItemStack(BloodMagicItems.DAGGER_OF_SACRIFICE.get()), AltarTier.TWO.ordinal(), 3000, 5, 5).build(consumer, BloodMagic.rl(basePath + "daggerofsacrifice")); diff --git a/src/main/java/wayoftime/bloodmagic/tile/TileAlchemicalReactionChamber.java b/src/main/java/wayoftime/bloodmagic/tile/TileAlchemicalReactionChamber.java index 06be3d0e..059d643a 100644 --- a/src/main/java/wayoftime/bloodmagic/tile/TileAlchemicalReactionChamber.java +++ b/src/main/java/wayoftime/bloodmagic/tile/TileAlchemicalReactionChamber.java @@ -1,19 +1,26 @@ package wayoftime.bloodmagic.tile; +import java.util.ArrayList; +import java.util.List; + import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerInventory; import net.minecraft.inventory.container.Container; import net.minecraft.inventory.container.INamedContainerProvider; +import net.minecraft.item.ItemStack; import net.minecraft.nbt.CompoundNBT; import net.minecraft.tileentity.ITickableTileEntity; import net.minecraft.tileentity.TileEntityType; import net.minecraft.util.text.ITextComponent; import net.minecraft.util.text.StringTextComponent; +import net.minecraftforge.fluids.FluidActionResult; import net.minecraftforge.fluids.FluidAttributes; +import net.minecraftforge.fluids.FluidUtil; import net.minecraftforge.fluids.capability.templates.FluidTank; import net.minecraftforge.registries.ObjectHolder; import wayoftime.bloodmagic.tile.contailer.ContainerAlchemicalReactionChamber; import wayoftime.bloodmagic.util.Constants; +import wayoftime.bloodmagic.util.MultiSlotItemHandler; public class TileAlchemicalReactionChamber extends TileInventory implements ITickableTileEntity, INamedContainerProvider { @@ -27,10 +34,8 @@ public class TileAlchemicalReactionChamber extends TileInventory implements ITic public static final int INPUT_BUCKET_SLOT = 7; public static final int OUTPUT_BUCKET_SLOT = 8; - public FluidTank inputTank = new FluidTank(FluidAttributes.BUCKET_VOLUME * 2); - public FluidTank outputTank = new FluidTank(FluidAttributes.BUCKET_VOLUME * 2); - -// Input slots are from 0 to 3. + public FluidTank inputTank = new FluidTank(FluidAttributes.BUCKET_VOLUME * 20); + public FluidTank outputTank = new FluidTank(FluidAttributes.BUCKET_VOLUME * 20); public int burnTime = 0; @@ -50,6 +55,12 @@ public class TileAlchemicalReactionChamber extends TileInventory implements ITic super.deserialize(tag); burnTime = tag.getInt(Constants.NBT.SOUL_FORGE_BURN); + + CompoundNBT inputTankTag = tag.getCompound("inputtank"); + inputTank.readFromNBT(inputTankTag); + + CompoundNBT outputTankTag = tag.getCompound("outputtank"); + inputTank.readFromNBT(outputTankTag); } @Override @@ -58,13 +69,53 @@ public class TileAlchemicalReactionChamber extends TileInventory implements ITic super.serialize(tag); tag.putInt(Constants.NBT.SOUL_FORGE_BURN, burnTime); + + CompoundNBT inputTankTag = new CompoundNBT(); + inputTank.writeToNBT(inputTankTag); + tag.put("inputtank", inputTankTag); + + CompoundNBT outputTankTag = new CompoundNBT(); + inputTank.writeToNBT(outputTankTag); + tag.put("outputtank", outputTankTag); + return tag; } @Override public void tick() { + if (world.isRemote) + { + return; + } + ItemStack bucketStack = this.getStackInSlot(INPUT_BUCKET_SLOT); + ItemStack[] outputInventory = new ItemStack[] + { getStackInSlot(1), getStackInSlot(2), getStackInSlot(3), getStackInSlot(4), getStackInSlot(5) }; + + MultiSlotItemHandler outputSlotHandler = new MultiSlotItemHandler(outputInventory, 64); +// FluidActionResult res = FluidUtil.tryEmptyContainerAndStow(bucketStack, inputTank, outputSlotHandler, 1000, null, false); + FluidActionResult res = FluidUtil.tryEmptyContainerAndStow(bucketStack, inputTank, outputSlotHandler, 1000, null, true); + if (res.isSuccess()) + { +// FluidUtil.tryEmptyContainerAndStow(bucketStack, inputTank, outputSlotHandler, 1000, null, true); + this.setInventorySlotContents(INPUT_BUCKET_SLOT, ItemStack.EMPTY); + + if (!res.getResult().isEmpty()) + { + List arrayList = new ArrayList<>(); + arrayList.add(res.getResult()); + + outputSlotHandler.canTransferAllItemsToSlots(arrayList, false); + } + } + + for (int i = 0; i < NUM_OUTPUTS; i++) + { + this.setInventorySlotContents(OUTPUT_SLOT + i, outputSlotHandler.getStackInSlot(i)); + } + +// FluidUtil.tryEmptyContainer(container, fluidDestination, maxAmount, player, doDrain) } // private boolean canCraft(RecipeTartaricForge recipe) diff --git a/src/main/java/wayoftime/bloodmagic/util/MultiSlotItemHandler.java b/src/main/java/wayoftime/bloodmagic/util/MultiSlotItemHandler.java new file mode 100644 index 00000000..65e41136 --- /dev/null +++ b/src/main/java/wayoftime/bloodmagic/util/MultiSlotItemHandler.java @@ -0,0 +1,291 @@ +package wayoftime.bloodmagic.util; + +import java.util.List; + +import javax.annotation.Nonnull; + +import net.minecraft.item.ItemStack; +import net.minecraftforge.items.IItemHandler; +import net.minecraftforge.items.ItemHandlerHelper; + +public class MultiSlotItemHandler implements IItemHandler +{ + private ItemStack[] items; + + private final int invLimit; + + public MultiSlotItemHandler(int size, int invLimit) + { + items = new ItemStack[size]; + for (int i = 0; i < size; i++) + { + items[i] = ItemStack.EMPTY; + } + + this.invLimit = invLimit; + } + + public MultiSlotItemHandler(ItemStack[] items, int invLimit) + { + this.items = items; + this.invLimit = invLimit; + } + + @Override + public int getSlots() + { + return items.length; + } + + @Override + public ItemStack getStackInSlot(int slot) + { + return items[slot]; + } + + public boolean isItemValid(int slot, ItemStack stack) + { + return true; + } + + public void setInventorySlotContents(int slot, ItemStack stack) + { + items[slot] = stack; + } + + @Override + @Nonnull + public ItemStack insertItem(int slot, @Nonnull ItemStack stack, boolean simulate) + { + if (stack.isEmpty()) + return ItemStack.EMPTY; + + ItemStack stackInSlot = getStackInSlot(slot); + + int m; + if (!stackInSlot.isEmpty()) + { + if (stackInSlot.getCount() >= Math.min(stackInSlot.getMaxStackSize(), getSlotLimit(slot))) + return stack; + + if (!ItemHandlerHelper.canItemStacksStack(stack, stackInSlot)) + return stack; + + if (!isItemValid(slot, stack)) + return stack; + + m = Math.min(stack.getMaxStackSize(), getSlotLimit(slot)) - stackInSlot.getCount(); + + if (stack.getCount() <= m) + { + if (!simulate) + { + ItemStack copy = stack.copy(); + copy.grow(stackInSlot.getCount()); + setInventorySlotContents(slot, copy); + } + + return ItemStack.EMPTY; + } else + { + // copy the stack to not modify the original one + stack = stack.copy(); + if (!simulate) + { + ItemStack copy = stack.split(m); + copy.grow(stackInSlot.getCount()); + setInventorySlotContents(slot, copy); + return stack; + } else + { + stack.shrink(m); + return stack; + } + } + } else + { + if (!isItemValid(slot, stack)) + return stack; + + m = Math.min(stack.getMaxStackSize(), getSlotLimit(slot)); + if (m < stack.getCount()) + { + // copy the stack to not modify the original one + stack = stack.copy(); + if (!simulate) + { + setInventorySlotContents(slot, stack.split(m)); + return stack; + } else + { + stack.shrink(m); + return stack; + } + } else + { + if (!simulate) + { + setInventorySlotContents(slot, stack); + } + return ItemStack.EMPTY; + } + } + } + + public boolean canTransferAllItemsToSlots(List stackList, boolean simulate) + { + ItemStack[] copyList = new ItemStack[items.length]; + for (int i = 0; i < copyList.length; i++) + { + copyList[i] = items[i].copy(); + } + + for (ItemStack stack : stackList) + { + if (stack.isEmpty()) + { + continue; + } + + slots: for (int slot = 0; slot < copyList.length; slot++) + { + ItemStack stackInSlot = copyList[slot]; + + int m; + if (!stackInSlot.isEmpty()) + { + if (stackInSlot.getCount() >= Math.min(stackInSlot.getMaxStackSize(), getSlotLimit(slot))) + continue; + + if (!ItemHandlerHelper.canItemStacksStack(stack, stackInSlot)) + continue; + + if (!isItemValid(slot, stack)) + continue; + + m = Math.min(stack.getMaxStackSize(), getSlotLimit(slot)) - stackInSlot.getCount(); + + if (stack.getCount() <= m) + { + if (!simulate) + { + ItemStack copy = stack.copy(); + copy.grow(stackInSlot.getCount()); + copyList[slot] = copy; + } + + break slots; + } else + { + // copy the stack to not modify the original one + stack = stack.copy(); + if (!simulate) + { + ItemStack copy = stack.split(m); + copy.grow(stackInSlot.getCount()); + copyList[slot] = copy; + } else + { + stack.shrink(m); + } + } + } else + { + if (!isItemValid(slot, stack)) + continue; + + m = Math.min(stack.getMaxStackSize(), getSlotLimit(slot)); + if (m < stack.getCount()) + { + // copy the stack to not modify the original one + stack = stack.copy(); + if (!simulate) + { + copyList[slot] = stack.split(m); + } else + { + stack.shrink(m); + } + } else + { + if (!simulate) + { + copyList[slot] = stack; + } + + stack = ItemStack.EMPTY; + } + } + } + + if (!stack.isEmpty()) + { + break; + } + } + + if (!simulate) + { + items = copyList; + } + + return false; + } + + @Override + @Nonnull + public ItemStack extractItem(int slot, int amount, boolean simulate) + { + if (amount == 0) + return ItemStack.EMPTY; + + ItemStack stackInSlot = getStackInSlot(slot); + + if (stackInSlot.isEmpty()) + return ItemStack.EMPTY; + + if (simulate) + { + if (stackInSlot.getCount() < amount) + { + return stackInSlot.copy(); + } else + { + ItemStack copy = stackInSlot.copy(); + copy.setCount(amount); + return copy; + } + } else + { + int m = Math.min(stackInSlot.getCount(), amount); + + ItemStack decrStackSize = decrStackSize(slot, m); + return decrStackSize; + } + } + + public ItemStack decrStackSize(int slot, int amount) + { + if (!getStackInSlot(slot).isEmpty()) + { + if (getStackInSlot(slot).getCount() <= amount) + { + ItemStack itemStack = getStackInSlot(slot); + setInventorySlotContents(slot, ItemStack.EMPTY); + return itemStack; + } + + ItemStack itemStack = getStackInSlot(slot).split(amount); + return itemStack; + } + + return ItemStack.EMPTY; + } + + @Override + public int getSlotLimit(int slot) + { + return invLimit; + } + +} diff --git a/src/main/java/wayoftime/bloodmagic/util/handler/event/ClientHandler.java b/src/main/java/wayoftime/bloodmagic/util/handler/event/ClientHandler.java index 033cc947..68976382 100644 --- a/src/main/java/wayoftime/bloodmagic/util/handler/event/ClientHandler.java +++ b/src/main/java/wayoftime/bloodmagic/util/handler/event/ClientHandler.java @@ -1,5 +1,6 @@ package wayoftime.bloodmagic.util.handler.event; +import java.util.HashMap; import java.util.List; import com.google.common.collect.Lists; @@ -9,30 +10,44 @@ import com.mojang.blaze3d.vertex.IVertexBuilder; import net.minecraft.client.Minecraft; import net.minecraft.client.entity.player.ClientPlayerEntity; +import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.renderer.ActiveRenderInfo; import net.minecraft.client.renderer.Atlases; import net.minecraft.client.renderer.IRenderTypeBuffer; +import net.minecraft.client.renderer.RenderType; +import net.minecraft.client.renderer.Tessellator; import net.minecraft.client.renderer.texture.AtlasTexture; import net.minecraft.client.renderer.texture.OverlayTexture; import net.minecraft.client.renderer.texture.TextureAtlasSprite; +import net.minecraft.inventory.container.PlayerContainer; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.Direction; import net.minecraft.util.ResourceLocation; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockRayTraceResult; import net.minecraft.util.math.RayTraceResult; +import net.minecraft.util.math.vector.Matrix4f; import net.minecraft.util.math.vector.Vector3d; +import net.minecraft.util.text.IFormattableTextComponent; +import net.minecraft.util.text.ITextComponent; +import net.minecraft.util.text.StringTextComponent; +import net.minecraft.util.text.Style; +import net.minecraft.util.text.TextFormatting; +import net.minecraft.util.text.TranslationTextComponent; import net.minecraft.world.World; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.client.event.RenderWorldLastEvent; import net.minecraftforge.client.event.TextureStitchEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fluids.IFluidTank; import net.minecraftforge.fml.common.Mod; import wayoftime.bloodmagic.BloodMagic; import wayoftime.bloodmagic.client.render.BloodMagicRenderer; import wayoftime.bloodmagic.client.render.BloodMagicRenderer.Model3D; import wayoftime.bloodmagic.client.render.RenderResizableCuboid; +import wayoftime.bloodmagic.client.utils.BMRenderTypes; import wayoftime.bloodmagic.common.item.ItemRitualDiviner; import wayoftime.bloodmagic.ritual.Ritual; import wayoftime.bloodmagic.ritual.RitualComponent; @@ -62,6 +77,36 @@ public class ClientHandler private static Direction mrsHoloDirection; private static boolean mrsHoloDisplay; + static HashMap resourceMap = new HashMap(); + + public static Minecraft mc() + { + return Minecraft.getInstance(); + } + + public static void bindTexture(String path) + { + mc().getTextureManager().bindTexture(getResource(path)); + } + + public static void bindAtlas() + { + mc().getTextureManager().bindTexture(PlayerContainer.LOCATION_BLOCKS_TEXTURE); + } + + public static ResourceLocation getResource(String path) + { + ResourceLocation rl = resourceMap.containsKey(path) ? resourceMap.get(path) : new ResourceLocation(path); + if (!resourceMap.containsKey(path)) + resourceMap.put(path, rl); + return rl; + } + + public static TextureAtlasSprite getSprite(ResourceLocation rl) + { + return mc().getModelManager().getAtlasTexture(PlayerContainer.LOCATION_BLOCKS_TEXTURE).getSprite(rl); + } + @SubscribeEvent public static void onTextureStitch(TextureStitchEvent.Pre event) { @@ -297,4 +342,138 @@ public class ClientHandler mrsHoloRitual = null; mrsHoloDirection = Direction.NORTH; } + + public static void handleGuiTank(MatrixStack transform, IFluidTank tank, int x, int y, int w, int h, int oX, int oY, int oW, int oH, int mX, int mY, String originalTexture, List tooltip) + { + handleGuiTank(transform, tank.getFluid(), tank.getCapacity(), x, y, w, h, oX, oY, oW, oH, mX, mY, originalTexture, tooltip); + } + + public static void handleGuiTank(MatrixStack transform, FluidStack fluid, int capacity, int x, int y, int w, int h, int oX, int oY, int oW, int oH, int mX, int mY, String originalTexture, List tooltip) + { + if (tooltip == null) + { + transform.push(); + IRenderTypeBuffer.Impl buffer = IRenderTypeBuffer.getImpl(Tessellator.getInstance().getBuffer()); + if (fluid != null && fluid.getFluid() != null) + { + int fluidHeight = (int) (h * (fluid.getAmount() / (float) capacity)); + drawRepeatedFluidSpriteGui(buffer, transform, fluid, x, y + h - fluidHeight, w, fluidHeight); + RenderSystem.color3f(1, 1, 1); + } + int xOff = (w - oW) / 2; + int yOff = (h - oH) / 2; + RenderType renderType = BMRenderTypes.getGui(new ResourceLocation(originalTexture)); + drawTexturedRect(buffer.getBuffer(renderType), transform, x + xOff, y + yOff, oW, oH, 256f, oX, oX + + oW, oY, oY + oH); + buffer.finish(renderType); + transform.pop(); + } else + { + if (mX >= x && mX < x + w && mY >= y && mY < y + h) + addFluidTooltip(fluid, tooltip, capacity); + } + } + + public static void drawRepeatedFluidSpriteGui(IRenderTypeBuffer buffer, MatrixStack transform, FluidStack fluid, float x, float y, float w, float h) + { + RenderType renderType = BMRenderTypes.getGui(PlayerContainer.LOCATION_BLOCKS_TEXTURE); + IVertexBuilder builder = buffer.getBuffer(renderType); + drawRepeatedFluidSprite(builder, transform, fluid, x, y, w, h); + } + + public static void drawRepeatedFluidSprite(IVertexBuilder builder, MatrixStack transform, FluidStack fluid, float x, float y, float w, float h) + { + TextureAtlasSprite sprite = getSprite(fluid.getFluid().getAttributes().getStillTexture(fluid)); + int col = fluid.getFluid().getAttributes().getColor(fluid); + int iW = sprite.getWidth(); + int iH = sprite.getHeight(); + if (iW > 0 && iH > 0) + drawRepeatedSprite(builder, transform, x, y, w, h, iW, iH, sprite.getMinU(), sprite.getMaxU(), sprite.getMinV(), sprite.getMaxV(), (col >> 16 + & 255) / 255.0f, (col >> 8 & 255) / 255.0f, (col & 255) / 255.0f, 1); + } + + public static void drawRepeatedSprite(IVertexBuilder builder, MatrixStack transform, float x, float y, float w, float h, int iconWidth, int iconHeight, float uMin, float uMax, float vMin, float vMax, float r, float g, float b, float alpha) + { + int iterMaxW = (int) (w / iconWidth); + int iterMaxH = (int) (h / iconHeight); + float leftoverW = w % iconWidth; + float leftoverH = h % iconHeight; + float leftoverWf = leftoverW / (float) iconWidth; + float leftoverHf = leftoverH / (float) iconHeight; + float iconUDif = uMax - uMin; + float iconVDif = vMax - vMin; + for (int ww = 0; ww < iterMaxW; ww++) + { + for (int hh = 0; hh < iterMaxH; hh++) drawTexturedRect(builder, transform, x + ww * iconWidth, y + + hh * iconHeight, iconWidth, iconHeight, r, g, b, alpha, uMin, uMax, vMin, vMax); + drawTexturedRect(builder, transform, x + ww * iconWidth, y + + iterMaxH * iconHeight, iconWidth, leftoverH, r, g, b, alpha, uMin, uMax, vMin, (vMin + + iconVDif * leftoverHf)); + } + if (leftoverW > 0) + { + for (int hh = 0; hh < iterMaxH; hh++) drawTexturedRect(builder, transform, x + iterMaxW * iconWidth, y + + hh * iconHeight, leftoverW, iconHeight, r, g, b, alpha, uMin, (uMin + + iconUDif * leftoverWf), vMin, vMax); + drawTexturedRect(builder, transform, x + iterMaxW * iconWidth, y + + iterMaxH * iconHeight, leftoverW, leftoverH, r, g, b, alpha, uMin, (uMin + + iconUDif * leftoverWf), vMin, (vMin + iconVDif * leftoverHf)); + } + } + + public static void drawTexturedRect(IVertexBuilder builder, MatrixStack transform, float x, float y, float w, float h, float r, float g, float b, float alpha, float u0, float u1, float v0, float v1) + { + Matrix4f mat = transform.getLast().getMatrix(); + builder.pos(mat, x, y + + h, 0).color(r, g, b, alpha).tex(u0, v1).overlay(OverlayTexture.NO_OVERLAY).lightmap(0xf000f0).normal(1, 1, 1).endVertex(); + builder.pos(mat, x + w, y + + h, 0).color(r, g, b, alpha).tex(u1, v1).overlay(OverlayTexture.NO_OVERLAY).lightmap(15728880).normal(1, 1, 1).endVertex(); + builder.pos(mat, x + + w, y, 0).color(r, g, b, alpha).tex(u1, v0).overlay(OverlayTexture.NO_OVERLAY).lightmap(15728880).normal(1, 1, 1).endVertex(); + builder.pos(mat, x, y, 0).color(r, g, b, alpha).tex(u0, v0).overlay(OverlayTexture.NO_OVERLAY).lightmap(15728880).normal(1, 1, 1).endVertex(); + } + + public static void drawTexturedRect(IVertexBuilder builder, MatrixStack transform, int x, int y, int w, int h, float picSize, int u0, int u1, int v0, int v1) + { + drawTexturedRect(builder, transform, x, y, w, h, 1, 1, 1, 1, u0 / picSize, u1 / picSize, v0 / picSize, v1 + / picSize); + } + + public static void addFluidTooltip(FluidStack fluid, List tooltip, int tankCapacity) + { + if (!fluid.isEmpty()) + tooltip.add(applyFormat(fluid.getDisplayName(), fluid.getFluid().getAttributes().getRarity(fluid).color)); + else + tooltip.add(new TranslationTextComponent("gui.bloodmagic.empty")); +// if (fluid.getFluid() instanceof IEFluid) +// ((IEFluid) fluid.getFluid()).addTooltipInfo(fluid, null, tooltip); + + if (mc().gameSettings.advancedItemTooltips && !fluid.isEmpty()) + { + if (!Screen.hasShiftDown()) + tooltip.add(new TranslationTextComponent("tooltip.bloodmagic.holdShiftForInfo")); + else + { + // TODO translation keys + tooltip.add(applyFormat(new StringTextComponent("Fluid Registry: " + fluid.getFluid().getRegistryName()), TextFormatting.DARK_GRAY)); + tooltip.add(applyFormat(new StringTextComponent("Density: " + fluid.getFluid().getAttributes().getDensity(fluid)), TextFormatting.DARK_GRAY)); + tooltip.add(applyFormat(new StringTextComponent("Temperature: " + fluid.getFluid().getAttributes().getTemperature(fluid)), TextFormatting.DARK_GRAY)); + tooltip.add(applyFormat(new StringTextComponent("Viscosity: " + fluid.getFluid().getAttributes().getViscosity(fluid)), TextFormatting.DARK_GRAY)); + tooltip.add(applyFormat(new StringTextComponent("NBT Data: " + fluid.getTag()), TextFormatting.DARK_GRAY)); + } + } + + if (tankCapacity > 0) + tooltip.add(applyFormat(new StringTextComponent(fluid.getAmount() + "/" + tankCapacity + "mB"), TextFormatting.GRAY)); + else + tooltip.add(applyFormat(new StringTextComponent(fluid.getAmount() + "mB"), TextFormatting.GRAY)); + } + + public static IFormattableTextComponent applyFormat(ITextComponent component, TextFormatting... color) + { + Style style = component.getStyle(); + for (TextFormatting format : color) style = style.applyFormatting(format); + return component.deepCopy().setStyle(style); + } + }