Jump to content
Search In
  • More options...
Find results that contain...
Find results in...


  • Posts

  • Joined

  • Last visited


  • Gender

TheMCJavaFre4k's Achievements

Stone Miner

Stone Miner (3/8)



  1. My repository if found here: https://bitbucket.org/TheMCJavaFre4k/mcdjmod/src/master/ Will probably swap to using a better ID system for my entities but just thought 0 would suffice for the single entity in testing.
  2. Ive now moved to EntityEntryBuilder for entity registration, but as expected, it has not changed the situation. The entity still doesn't have a bounding box or is rendered in any way but is being spawned. New Entity registration code: public static void registerEntity(RegistryEvent.Register<EntityEntry> reg){ EntityEntry entityScreen = EntityEntryBuilder.create().entity(EntityScreen.class).id(new ResourceLocation(MCDJMod.modId, "screenentity"), 0).name("screenentity").tracker(160, Integer.MAX_VALUE, true).build(); reg.getRegistry().register(entityScreen); } Any suggestions are appreciated.
  3. Hi There Ive been trying to create a identical painting item to default minecraft to later modify with custom rendering. Currently I've made a copy of the Entity, Render and Item classes and registered them(See below). With this code how it is, The entity seems to spawn as it has the behaviour of a minecraft painting, ie - breaks off the wall if a block behind is removed, but has no hitbox and is not rendered. I have tried finding information on this topic but since a custom painting item is such a niche thing to need, I haven't had much luck. Im hoping its just a registration problem and a simple fix. Any suggestions are welcome! EntityScreen: RenderScreen: ItemScreen: Renderer Registration in ClientProxy: RenderingRegistry.registerEntityRenderingHandler(EntityScreen.class, new RenderScreenFactory()); RenderScreenFactory: public class RenderScreenFactory implements IRenderFactory<EntityScreen> { @Override public Render<? super EntityScreen> createRenderFor(RenderManager manager) { return new RenderScreen(manager); } } Entity Registration called in PreInit: EntityRegistry.registerModEntity(new ResourceLocation("mcdj", "screenentity"), EntityScreen.class, "screenEntity", 0, MCDJMod.instance, 160, Integer.MAX_VALUE, false); If any more information is required, let me know.
  4. I totally forgot to check if I could use the sound to stop itself. I guess I just had tunnel vision when looking at the problem. Considering my custom sound is a tickable sound, this works flawlessly. Thanks heaps!
  5. Indeed, probably should have worded it with int so to not confuse it with the class.
  6. By counter, I believe DavidM is suggesting you use a type such as an Integer which is incremented by 1(int++) within update(). You would then have the if statement check the value of this Integer and if it reaches 5, set it back to 0.
  7. I haven't dealt with any Events thus far other than the standard registration ones so I wouldn't know where to begin. They current way I'm dealing with sounds is by using a custom MovingSound class(So to update positioning) being played by Minecraft.getMinecraft().getSoundHandler().playSound(). I can then stop it by passing in the exact same sound. This allows me to differentiate the exact same sound being played from 2 TileEntities and stop them independent of one another. Is this same functionality obtainable using a @SubscribeEvent and subscribing to the PlaySoundEvent class?
  8. My tile entity has a few methods responsible for stopping sound playback. The packet is used to update all nearby clients to stop any sound the TileEntity is making before it is removed. So in the packet handler I'm getting the TileEntity from the position sent over the packet and calling my methods on the client from there.
  9. Hi There Im wanting to prevent the tile entity of a block from being removed until after Ive executed some code within the tile entity via a custom packet. Im able to get this working in survival mode by sending the packet within the getDrops method and delaying removal until the harvestBlock method(Similar to blockFlowerPot) as so: Currently when broken in creative, nothing happens(Only breaking particles). I was initially using breakBlock but that didn't provide enough time for the packet to be read and when it was, the tile entity at the BlockPos was already removed. Im just not sure what methods would provide the necessary time or how i would modify the above setup to work for creative mode.
  10. Ive just used my container class to get the tile entity into the gui. Using: container.tileEntity.variables I just grab the variables I need straight from the tile entity. Not sure if this is the most correct way to do it but it works on both logical and physical servers with no issue.
  11. Thanks heaps for the reply, that would be the issue. Its now working as intended.
  12. Hi There Im currently sending packets from a tile entity to all nearby clients to play sounds(This is necessary over traditional playSound methods due to high control over the sound). On a single player world, everything works as expected and the debug printouts within the code come from the expected sides. When running on a dedicated server, the packet constructor and toBytes() are both called with correct data but nothing happens following that. No code within the Packet Handler is executed and neither is fromBytes(). PacketPlaySoundOnClient: ClientSoundHandler: Registering packet in my ClientProxy(Only packet with id 11): MCDJMod.network.registerMessage(ClientSoundHandler.class, PacketPlaySoundOnClient.class, 11, Side.CLIENT); Calling send method: On a side not, If i leave out the instruction integer from my packet, I get the following IndexOutOfBoundException from the client followed by disconnection from the server: readerIndex(11) + length(2) exceeds writerIndex(12): UnpooledSlicedByteBuf(ridx: 11, widx: 12, cap: 12/12, unwrapped: PooledUnsafeDirectByteBuf(ridx: 0, widx: 13, cap: 13)) Not sure if this may have something to do with the issue.
  13. Thanks so much for sharing that. I added the INBTInventory implementation to handle the NBT tags and everything is working perfectly now. Couldn't thank you enough!
  14. The only real similar one i found was the one i referenced in the post. All others seem to be regarding tile entities with the same issues. Will have another look though.
  15. Hi there My aim was to create a single slot inventory when an item was right clicked. Im good with all the gui stuff but can seem to nail the capabilities and NBT. I found this post( I also don't know using the current setup how I would go about accessing the contents of the slot from within the item class. Any guidance is appreciated. Code: ItemClass: package net.themcjavafre4k.mcdj.item.headphones; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.EntityEquipmentSlot; import net.minecraft.item.ItemArmor; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.ActionResult; import net.minecraft.util.EnumActionResult; import net.minecraft.util.EnumHand; import net.minecraft.world.World; import net.minecraftforge.common.capabilities.ICapabilityProvider; import net.minecraftforge.items.CapabilityItemHandler; import net.minecraftforge.items.IItemHandler; import net.themcjavafre4k.mcdj.MCDJGuiHandler; import net.themcjavafre4k.mcdj.MCDJMod; import net.themcjavafre4k.mcdj.item.CustomRecord; import net.themcjavafre4k.mcdj.item.MCDJItems; public class ItemHeadphones extends ItemArmor{ private String title; public ItemHeadphones(String name){ super(MCDJItems.headphoneMaterial, 1, EntityEquipmentSlot.HEAD); this.title = name; setUnlocalizedName(name); setRegistryName(name); setCreativeTab(MCDJMod.creativeTab); INSTANCE = this; } public void registerItemModel(){ MCDJMod.proxy.registerItemRenderer(this, 0, title, "mcdj"); } @Override public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand){ ItemStack itemstack = player.getHeldItem(hand); if (!world.isRemote){ player.openGui(MCDJMod.instance, MCDJGuiHandler.HEADPHONES, world, (int)player.posX, (int)player.posY, (int)player.posZ); //LogHelper.info("Succesfully opened GUI"); } return new ActionResult<ItemStack>(EnumActionResult.PASS, player.getHeldItemMainhand()); } @Override public ICapabilityProvider initCapabilities( ItemStack item, NBTTagCompound nbt ) { return new HeadphonesProvider(); } } Provider: package net.themcjavafre4k.mcdj.item.headphones; import net.minecraft.nbt.NBTBase; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.EnumFacing; import net.minecraftforge.common.capabilities.Capability; import net.minecraftforge.common.capabilities.ICapabilityProvider; import net.minecraftforge.common.capabilities.ICapabilitySerializable; import net.minecraftforge.items.CapabilityItemHandler; import net.minecraftforge.items.ItemStackHandler; public class HeadphonesProvider implements ICapabilityProvider, ICapabilitySerializable<NBTTagCompound>{ private ItemStackHandler inventory; public HeadphonesProvider() { inventory = new ItemStackHandler(1); } @Override public NBTTagCompound serializeNBT() { return inventory.serializeNBT(); } @Override public void deserializeNBT( NBTTagCompound nbt ) { // nbt = new NBTTagCompound(); inventory.deserializeNBT(nbt); } @Override public boolean hasCapability( Capability<?> capability, EnumFacing facing ) { if( capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY ) { return true; } return false; } @Override public <T> T getCapability( Capability<T> capability, EnumFacing facing ) { if( capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY ) { return (T) inventory; } return null; } } Container: package net.themcjavafre4k.mcdj.item.headphones; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.Container; import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraftforge.items.IItemHandler; import net.themcjavafre4k.mcdj.inventory.SlotInput; import net.themcjavafre4k.mcdj.item.CustomRecord; import net.themcjavafre4k.mcdj.item.MCDJItems; public class ContainerHeadphones extends Container{ public IItemHandler inv; public ContainerHeadphones(IItemHandler itemHandler, EntityPlayer player ) { this.inv = itemHandler; addSlotToContainer(new SlotInput(itemHandler, 0, 44, 35)); for(int i = 0; i < 3; i++){ for(int j = 0; j < 9; j++){ addSlotToContainer(new Slot(player.inventory, j+i*9+9, 8+j*18, 84+i*18)); } } for(int i = 0; i < 9; i++){ addSlotToContainer(new Slot(player.inventory, i, 8+i*18, 142)); } } @Override public boolean canInteractWith(EntityPlayer playerIn) { return true; } //Crashing game // @Nullable // @Override // public ItemStack transferStackInSlot(EntityPlayer playerIn, int index) // { // ItemStack itemstack = ItemStack.EMPTY; // Slot slot = this.inventorySlots.get(index); // // if (slot != null && slot.getHasStack()) // { // ItemStack itemstack1 = slot.getStack(); // itemstack = itemstack1.copy(); // // if (index == 2) // { // if (!this.mergeItemStack(itemstack1, 3, 39, true)) // { // return ItemStack.EMPTY; // } // // slot.onSlotChange(itemstack1, itemstack); // } // else if (!this.mergeItemStack(itemstack1, 3, 39, false)) // { // return ItemStack.EMPTY; // } // // if (itemstack1.isEmpty()) // { // slot.putStack(ItemStack.EMPTY); // } // else // { // slot.onSlotChanged(); // } // // if (itemstack1.getCount() == itemstack.getCount()) // { // return ItemStack.EMPTY; // } // // slot.onTake(playerIn, itemstack1); // } // // return itemstack; // } } SlotInput: package net.themcjavafre4k.mcdj.inventory; import javax.annotation.Nonnull; import net.minecraft.item.ItemStack; import net.minecraftforge.items.IItemHandler; import net.minecraftforge.items.SlotItemHandler; import net.themcjavafre4k.mcdj.item.CustomRecord; import net.themcjavafre4k.mcdj.item.MCDJItems; public class SlotInput extends SlotItemHandler { public SlotInput(IItemHandler inventory, int par2, int par3, int par4) { super(inventory, par2, par3, par4); } @Override public boolean isItemValid(ItemStack itemstack) { return itemstack.getItem() instanceof CustomRecord; //return true; } @Override public int getSlotStackLimit() { return 1; } } Gui: package net.themcjavafre4k.mcdj.item.headphones; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.inventory.GuiContainer; import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.resources.I18n; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.Container; import net.minecraft.util.ResourceLocation; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; import net.themcjavafre4k.mcdj.MCDJMod; import net.themcjavafre4k.mcdj.SoundHandler; import net.themcjavafre4k.mcdj.item.MCDJItems; @SideOnly(Side.CLIENT) public class GuiHeadphones extends GuiContainer{ private static final ResourceLocation BG_TEXTURE = new ResourceLocation(MCDJMod.modId, "textures/gui/headphonegui.png"); public GuiHeadphones(Container container, InventoryPlayer inventory) { super(container); } @Override public void initGui(){ super.initGui(); } @Override public void drawScreen(int mouseX, int mouseY, float partialTicks) { this.drawDefaultBackground(); super.drawScreen(mouseX, mouseY, partialTicks); this.renderHoveredToolTip(mouseX, mouseY); } @Override protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY){ GlStateManager.color(1, 1, 1, 1); mc.getTextureManager().bindTexture(BG_TEXTURE); int x = (width - xSize) / 2; int y = (height - ySize) / 2; drawTexturedModalRect(x, y, 0, 0, xSize, ySize); } @Override protected void drawGuiContainerForegroundLayer(int mousX, int mouseY){ String name = I18n.format(MCDJItems.headphones.getUnlocalizedName()); //fontRenderer.drawString("Search For Songs", 195, 4, 0xFFFFFF); fontRenderer.drawString("Headphone Player", (xSize/2 - fontRenderer.getStringWidth(name)/2), 5, 0xFFFFFF); //fontRenderer.drawString(invPlayer.getDisplayName().getUnformattedText(), 8, ySize/2 - 10, 0xFFFFFF); } } If any more information is needed I will provide.
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.