Jump to content

DeathSpawn

Members
  • Posts

    35
  • Joined

  • Last visited

Everything posted by DeathSpawn

  1. How do I make my Universal Bucket added by Forge have an overlay? Fluid class ublic class FluidEnchantedLiquid extends Fluid{ protected static int mapColor = 0xFFFFFFFF; protected static float overlayAlpha = 0.2F; protected static SoundEvent emptySound = SoundEvents.ITEM_BUCKET_EMPTY; protected static SoundEvent fillSound = SoundEvents.ITEM_BUCKET_FILL; protected static Material material = Material.WATER; public FluidEnchantedLiquid(String fluidName, ResourceLocation still, ResourceLocation flowing) { super(fluidName, still, flowing); ModFluids.FLUIDS.add(this); } public FluidEnchantedLiquid(String fluidName, ResourceLocation still, ResourceLocation flowing, int mapColor) { this(fluidName, still, flowing); setColor(mapColor); ModFluids.FLUIDS.add(this); } public FluidEnchantedLiquid(String fluidName, ResourceLocation still, ResourceLocation flowing, int mapColor, float overlayAlpha) { this(fluidName, still, flowing, mapColor); setAlpha(overlayAlpha); ModFluids.FLUIDS.add(this); } @Override public int getColor() { return mapColor; } public FluidEnchantedLiquid setColor(int parColor) { mapColor = parColor; return this; } public float getAlpha() { return overlayAlpha; } public FluidEnchantedLiquid setAlpha(float parOverlayAlpha) { overlayAlpha = parOverlayAlpha; return this; } @Override public FluidEnchantedLiquid setEmptySound(SoundEvent parSound) { emptySound = parSound; return this; } @Override public SoundEvent getEmptySound() { return emptySound; } @Override public FluidEnchantedLiquid setFillSound(SoundEvent parSound) { fillSound = parSound; return this; } @Override public SoundEvent getFillSound() { return fillSound; } public FluidEnchantedLiquid setMaterial(Material parMaterial) { material = parMaterial; return this; } public Material getMaterial() { return material; } @Override public boolean doesVaporize(FluidStack fluidStack) { if (block == null) return false; return block.getDefaultState().getMaterial() == getMaterial(); } } ModFluids class public class ModFluids { public static List<Fluid> FLUIDS = new ArrayList<Fluid>(); public static Fluid enchantedFluid = new FluidEnchantedLiquid("enchanted", new ResourceLocation(Reference.MOD_ID, "enchanted_still"), new ResourceLocation(Reference.MOD_ID, "enchanted_flow")).setMaterial(ModMaterials.ENCHANTED).setDensity(100).setGaseous(false).setLuminosity(2).setViscosity(25000).setTemperature(300); } How I registered my fluid: public static void onBlockRegister(RegistryEvent.Register<Block> event) { event.getRegistry().registerAll(ModBlocks.BLOCKS.toArray(new Block[0])); GameRegistry.registerTileEntity(((BlockRotatableBase) ModBlocks.enchanterGem).getTileEntityClass(), ModBlocks.enchanterGem.getRegistryName().toString()); for (Fluid fluid : ModFluids.FLUIDS) { boolean done = FluidRegistry.registerFluid(fluid); FluidRegistry.addBucketForFluid(fluid); if(done) { Utils.getLogger().info("Succcessful!"); } } } So, How do I add an overlay to the universal bucket?
  2. The event is supposed to be in the client proxy and you set client proxy to be a @EventBusSubsciber
  3. I have a Event Handler and I would like to register it. Does it matter in which FMLInitializationEvent I put in? Main Mod class @Mod(name = Reference.MOD_NAME, modid = Reference.MOD_ID, version = Reference.VERSION, acceptedMinecraftVersions = "1.12.2") public class GemEnchantmentMod { static { FluidRegistry.enableUniversalBucket(); } @SidedProxy(clientSide = Reference.CLIENT_PROXY, serverSide = Reference.SERVER_PROXY) public static CommonProxy proxy; public static final SimpleNetworkWrapper INSTANCE = NetworkRegistry.INSTANCE.newSimpleChannel("edm"); @Instance public static GemEnchantmentMod instance; public static GemEnchantmentModCreativeTab mainTab = new GemEnchantmentModCreativeTab("mainGemEnchantmentMod", new ItemStack(ModItems.fireGem, 1)); @EventHandler public static void PreInit(FMLPreInitializationEvent event) { } @EventHandler public static void Init(FMLInitializationEvent event) { proxy.init(); } @EventHandler public static void PostInit(FMLPostInitializationEvent event) { } } EventHandler class public class EventHandler { @SideOnly(Side.CLIENT) @SubscribeEvent(priority=EventPriority.NORMAL, receiveCanceled=true) public void onEvent(RenderGameOverlayEvent.Pre event) { if (event.getType() == ElementType.ALL) { EntityPlayer thePlayer = Minecraft.getMinecraft().player; if (thePlayer.isInsideOfMaterial(ModMaterials.ENCHANTED)) { drawFluidOverlay(ModFluids.enchantedFluid.getColor(), 0.2F); } } } /** * Draws a rectangle with the specified color */ @SideOnly(Side.CLIENT) public static void drawFluidOverlay(int parColor, float parAlpha) { int left = 0; int top = 0; int right = Minecraft.getMinecraft().displayWidth; int bottom = Minecraft.getMinecraft().displayHeight; Color color = Color.GREEN; Tessellator tessellator = Tessellator.getInstance(); BufferBuilder bufferbuilder = tessellator.getBuffer(); GlStateManager.enableBlend(); GlStateManager.disableTexture2D(); GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO); GlStateManager.color(color.getRed(), color.getGreen(), color.getBlue(), parAlpha); bufferbuilder.begin(7, DefaultVertexFormats.POSITION); bufferbuilder.pos(left, bottom, 0.0D).endVertex(); bufferbuilder.pos(right, bottom, 0.0D).endVertex(); bufferbuilder.pos(right, top, 0.0D).endVertex(); bufferbuilder.pos(left, top, 0.0D).endVertex(); tessellator.draw(); GlStateManager.enableTexture2D(); GlStateManager.disableBlend(); } }
  4. For people referring to this in the future, Use these methods used in my case : @Override public SPacketUpdateTileEntity getUpdatePacket(){ NBTTagCompound nbtTag = new NBTTagCompound(); nbtTag.setTag("inventory", inventory.serializeNBT()); energy.writeToNBT(nbtTag); nbtTag.setInteger("enchantTime", this.enchantTime); nbtTag.setInteger("currentItemEnchantTime", this.currentItemEnchantTime); nbtTag.setInteger("enchantingTime", this.enchantingTime); nbtTag.setInteger("shouldEnchantTime", this.shouldEnchantTime); nbtTag.setBoolean("isEnchanting", this.isEnchanting); return new SPacketUpdateTileEntity(getPos(), 1, nbtTag); } @Override public void onDataPacket(NetworkManager net, SPacketUpdateTileEntity pkt){ NBTTagCompound tag = pkt.getNbtCompound(); inventory.deserializeNBT(tag.getCompoundTag("inventory")); energy.readFromNBT(tag); this.enchantTime = tag.getInteger("enchantTime"); this.currentItemEnchantTime = tag.getInteger("currentItemEnchantTime"); this.enchantingTime = tag.getInteger("enchantingTime"); this.shouldEnchantTime = tag.getInteger("shouldEnchantTime"); this.isEnchanting = tag.getBoolean("isEnchanting"); } and also add the following in the update() method: if(this.world.isBlockLoaded(getPos())) { this.world.notifyBlockUpdate(getPos(), this.world.getBlockState(getPos()), this.world.getBlockState(getPos()), 2); } This should fix the problem I had
  5. The method has fixed the problem. Should I change the title to [Solved]... or something like that? I am new to the Minecraft Forge forums
  6. Not now. I am currently trying to do so. This might solve the problem I will update my code and see if it does
  7. Thanks! I will read through this and solve the problem...
  8. Sorry, but I don't understand what this statement means. How am I supposed to this?
  9. Thanks. Will try it. But is there any like client and server relationship that happens when executing the IInventory te.getField(int) ?
  10. Since I am using ItemHandlers I am not able to communicate using te.getField(int). Please provide an alternative to this problem. My Gui is working properly, just that I am not able to test whether the funace is active or not. TileEntityGemEnchanter.class public class TileEntityGemEnchanter extends TileEntityBase implements ITickable, ICapabilityProvider { private ItemStackHandler inventory = new ItemStackHandler(4); private DynamicEnergyStorage energy = new DynamicEnergyStorage(1000000); private boolean isEnchanting; private int enchantingTime; private int currentItemEnchantTime; private int enchantTime; private int shouldEnchantTime = 50; private String enchanterCustomName; private int counter = 0; @Override public NBTTagCompound writeToNBT(NBTTagCompound compound) { super.writeToNBT(compound); compound.setTag("inventory", inventory.serializeNBT()); energy.writeToNBT(compound); compound.setInteger("enchantTime", this.enchantTime); compound.setInteger("currentItemEnchantTime", this.currentItemEnchantTime); compound.setInteger("enchantingTime", this.enchantingTime); compound.setInteger("shouldEnchantTime", this.shouldEnchantTime); compound.setBoolean("isEnchanting", this.isEnchanting); if (this.hasCustomName()) { compound.setString("enchanterCustomName", this.enchanterCustomName); } return compound; } @Override public void readFromNBT(NBTTagCompound compound) { super.readFromNBT(compound); inventory.deserializeNBT(compound.getCompoundTag("inventory")); energy.readFromNBT(compound); this.enchantTime = compound.getInteger("enchantTime"); this.currentItemEnchantTime = compound.getInteger("currentItemEnchantTime"); this.enchantingTime = compound.getInteger("enchantingTime"); this.shouldEnchantTime = compound.getInteger("shouldEnchantTime"); this.isEnchanting = compound.getBoolean("isEnchanting"); if (compound.hasKey("CustomName", 8)) { this.enchanterCustomName = compound.getString("CustomName"); } } public boolean isEmpty() { for (int i = 0; i > this.inventory.getSlots(); i++) { if (!this.inventory.getStackInSlot(i).isEmpty()) { return false; } } return true; } public ItemStack decrStackSize(int index, int count) { return index >= 0 && index < this.inventory.getSlots() && !((ItemStack) this.inventory.getStackInSlot(index)).isEmpty() && count > 0 ? ((ItemStack) this.inventory.getStackInSlot(index)).splitStack(count) : ItemStack.EMPTY; } public ItemStack removeStackFromSlot(int index) { if (index >= 0 && index < this.inventory.getSlots()) { this.inventory.setStackInSlot(index, ItemStack.EMPTY); return ItemStack.EMPTY; } return ItemStack.EMPTY; } public String getName() { return this.hasCustomName() ? this.enchanterCustomName : "container.enchanter"; } public boolean hasCustomName() { return this.enchanterCustomName != null && !this.enchanterCustomName.isEmpty(); } public void setCustomInventoryName(String name) { this.enchanterCustomName = name; } public void setInventorySlotContents(int index, ItemStack stack) { ItemStack itemstack = this.inventory.getStackInSlot(index); boolean flag = !stack.isEmpty() && stack.isItemEqual(itemstack) && ItemStack.areItemStackTagsEqual(stack, itemstack); this.inventory.setStackInSlot(index, stack); if (stack.getCount() > 64) { stack.setCount(64); } if (index == 0 && !flag) { this.markDirty(); } } public ItemStack getStackInSlot(int index) { return this.inventory.getStackInSlot(index); } @Override public boolean hasCapability(Capability<?> capability, @Nullable EnumFacing facing) { return capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY || capability == CapabilityEnergy.ENERGY || super.hasCapability(capability, facing); } @Nullable @Override public <T> T getCapability(Capability<T> capability, @Nullable EnumFacing facing) { if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) return (T) this.inventory; else if (capability == CapabilityEnergy.ENERGY) return (T) this.energy; else return super.getCapability(capability, facing); } public boolean isEnchanting() { return isEnchanting; } @Override public void update() { if (!this.world.isRemote) { List<EntityItem> items = new ArrayList<EntityItem>(); items.addAll(world.getEntitiesWithinAABB(EntityItem.class, new AxisAlignedBB(pos.add(3, 3, 3), pos.add(-3, -3, -3)))); for (EntityItem item : items) { if (item.getItem().getItem() == Items.STICK) { Utils.getLogger().info("Added Power!"); this.energy.receiveEnergy(1000, false); } } if (this.canSmelt()) { this.currentItemEnchantTime = getEnchantTime(this.inventory.getStackInSlot(0), this.inventory.getStackInSlot(1)); this.shouldEnchantTime = this.currentItemEnchantTime; this.isEnchanting = true; this.smeltItem(); } else { this.enchantTime = 0; this.currentItemEnchantTime = 0; this.enchantingTime = 0; this.shouldEnchantTime = 0; this.isEnchanting = false; } } this.markDirty(); } public int getEnchantTime(ItemStack stack, ItemStack stack2) { return 50; } /** * Returns true if the furnace can smelt an item, i.e. has a source item, * destination stack isn't full, etc. */ private boolean canSmelt() { ItemStack slot0 = this.inventory.getStackInSlot(0); ItemStack slot1 = this.inventory.getStackInSlot(1); ItemStack slot2 = this.inventory.getStackInSlot(2); boolean canSmelt = false; if (!(slot0.isEmpty() && slot1.isEmpty())) { ItemStack recipes = GemEnchanterRecipes.instance().getEnchantingResult(slot0, slot1); if (recipes != ItemStack.EMPTY) { if (((slot2.getItem() == recipes.getItem() && slot2.getCount() < slot2.getItem().getItemStackLimit(slot2)) || slot2.isEmpty()) && this.energy.getEnergyStored() > 10) { canSmelt = true; } } } return canSmelt; } public void smeltItem() { ItemStack slot0 = this.inventory.getStackInSlot(0); ItemStack slot1 = this.inventory.getStackInSlot(1); ItemStack result = GemEnchanterRecipes.instance().getEnchantingResult(slot0, slot1); ItemStack slot2 = this.inventory.getStackInSlot(2); if (this.isEnchanting()) { if (this.enchantTime >= this.getShouldEnchantTime()) { slot0.shrink(1); slot1.shrink(1); if (slot2.isEmpty() || slot2.getItem() == Item.getItemFromBlock(Blocks.AIR)) { this.inventory.setStackInSlot(2, result.copy()); } else { slot2.grow(result.getCount()); } } else { this.enchantTime++; this.energy.extractEnergy(10, false); } } } public int getEnchantingTime() { return this.enchantingTime; } public void setEnchantingTime(int enchantingTime) { this.enchantingTime = enchantingTime; } public int getCurrentItemEnchantTime() { return this.currentItemEnchantTime; } public void setCurrentItemEnchantTime(int currentItemEnchantTime) { this.currentItemEnchantTime = currentItemEnchantTime; } public int getEnchantTime() { return this.enchantTime; } public void setEnchantTime(int enchantTime) { this.enchantTime = enchantTime; } public int getShouldEnchantTime() { return this.shouldEnchantTime; } public void setShouldEnchantTime(int shouldEnchantTime) { this.shouldEnchantTime = shouldEnchantTime; } public void setEnchanting(boolean isEnchanting) { this.isEnchanting = isEnchanting; } public boolean isItemValidForSlot(int index, ItemStack stack) { return index == 1 || index == 2; } } GuiGemEnchanter.class public class GuiGemEnchanter extends GuiContainer{ private TileEntityGemEnchanter te; private IInventory playerInv; public GuiGemEnchanter(InventoryPlayer playerInv, TileEntityGemEnchanter te) { super(new ContainerGemEnchanter(playerInv, te)); this.xSize = 175; this.ySize = 165; this.te = te; this.playerInv = playerInv; } @Override protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) { GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); this.mc.getTextureManager().bindTexture(new ResourceLocation(Reference.MOD_ID, "textures/gui/container/gem_enchanter.png")); this.drawTexturedModalRect(this.guiLeft, this.guiTop, 0, 0, this.xSize, this.ySize); int s = 0; if(!this.te.getWorld().isRemote) { s = te.getEnchantTime(); Utils.getLogger().info(te.getEnchantTime()); } if(s > 0) { Utils.getLogger().info("Reached here!"); this.drawTexturedModalRect(79, 34, 176, 14, this.getEnchantedAmount(), 17); } } @Override protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) { String s = GemEnchantmentMod.proxy.localize(te.getName()); //Gets the formatted name for the block breaker from the language file - NOTE ADD "container.block_breaker=Block Breaker" to the language file (without quotes) and then delete this note this.mc.fontRenderer.drawString(s, this.xSize / 2 - this.mc.fontRenderer.getStringWidth(s) / 2, 6, 4210752); this.mc.fontRenderer.drawString(this.playerInv.getDisplayName().getFormattedText(), 8, 72, 4210752); super.drawGuiContainerForegroundLayer(mouseX, mouseY); } private int getEnchantedAmount() { int currentItemEnchantAmount = this.te.getCurrentItemEnchantTime(); int enchantTime = this.te.getEnchantTime(); float percentage = enchantTime/currentItemEnchantAmount * 100; int amount = Math.round(percentage) * 24; return amount; } } BlockGemEnchanter.class ublic class BlockGemEnchanter extends BlockRotatableBase{ public BlockGemEnchanter(Material materialIn, String registryName, float resistance, float hardness, Class tileEntity) { super(materialIn, registryName, resistance, hardness, tileEntity); } @Override public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) { if(!worldIn.isRemote) { playerIn.openGui(GemEnchantmentMod.instance, GUI_ID.GEM_ENCHANTER.getGUI_ID(), worldIn, pos.getX(), pos.getY(), pos.getZ()); } return true; } }
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.