Jump to content

TobiasFiller

Members
  • Posts

    4
  • Joined

  • Last visited

TobiasFiller's Achievements

Tree Puncher

Tree Puncher (2/8)

0

Reputation

  1. Hi, i am having a problem with my BlockEntityRenderer. I am trying to render the Item that the BlockEntity is storing, but after i close and open the world again the itemRenderer dosn't render the item anymore. @OnlyIn(Dist.CLIENT) public class StonePedestalRenderer implements BlockEntityRenderer<StonePedestalBlockEntity> { public final ItemRenderer itemRenderer = Minecraft.getInstance().getItemRenderer(); public StonePedestalRenderer(BlockEntityRendererProvider.Context pContext){ } @Override public void render(StonePedestalBlockEntity pBlockEntity, float pPartialTick, PoseStack pPoseStack, MultiBufferSource pBufferSource, int pPackedLight, int pPackedOverlay) { ItemStack stack = new ItemStack(pBlockEntity.getItem()); if (!stack.isEmpty()){ pPoseStack.pushPose(); pPoseStack.translate(0.5D, 1.3225D, 0.5D); pPoseStack.scale(0.6f,0.6f,0.6f); float f3 = pBlockEntity.getSpin(pPartialTick); pPoseStack.mulPose(Vector3f.YP.rotationDegrees(f3)); itemRenderer.renderStatic(Minecraft.getInstance().player,stack, ItemTransforms.TransformType.FIXED,false,pPoseStack,pBufferSource,Minecraft.getInstance().level,pPackedLight,pPackedOverlay,0); pPoseStack.popPose(); } } } and here is the code fore the Block Entity: public class StonePedestalBlockEntity extends BlockEntity { protected ItemStackHandler itemHandler = new ItemStackHandler(1) { @Override protected void onContentsChanged(int slot) { setChanged(); } }; protected LazyOptional<IItemHandler> lazyItemHandler = LazyOptional.empty(); private float age = 0.0f; public final float bobOffs; private final Random random = new Random();; public StonePedestalBlockEntity(BlockPos pWorldPosition, BlockState pBlockState) { super(BlockEntityRegistry.STONE_PEDESTAL_BLOCK_ENTITY.get(), pWorldPosition, pBlockState); this.bobOffs = this.random.nextFloat() * (float)Math.PI * 2.0F; } public boolean setItem(ItemStack stack){ if (this.itemHandler.getStackInSlot(0).isEmpty()){ stack = new ItemStack(stack.getItem(),1); this.itemHandler.setStackInSlot(0,stack); return true; } return false; } public Item getItem(){ return this.itemHandler.getStackInSlot(0).getItem(); } public ItemStack getAndRemoveItem(){ if (!this.itemHandler.getStackInSlot(0).isEmpty()){ ItemStack stack = this.itemHandler.getStackInSlot(0); this.itemHandler.setStackInSlot(0,ItemStack.EMPTY); return stack; } return this.itemHandler.getStackInSlot(0); } public void removeItem(){ this.itemHandler.setStackInSlot(0,ItemStack.EMPTY); } public float getSpin(float pPartialTicks) { this.age += pPartialTicks; return (this.age) + this.bobOffs; } @NotNull @Override public <T> LazyOptional<T> getCapability(@NotNull Capability<T> cap, @Nullable Direction side) { if (cap == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY){ return lazyItemHandler.cast(); } return super.getCapability(cap, side); } @Override public void onLoad() { super.onLoad(); lazyItemHandler = LazyOptional.of(() -> itemHandler); } @Override public void invalidateCaps() { super.invalidateCaps(); lazyItemHandler.invalidate(); } @Override protected void saveAdditional(CompoundTag nbt) { nbt.put("inventory", itemHandler.serializeNBT()); super.saveAdditional(nbt); } @Override public void load(CompoundTag nbt) { super.load(nbt); itemHandler.deserializeNBT(nbt.getCompound("inventory")); } public void drops() { SimpleContainer inventory = new SimpleContainer(itemHandler.getSlots()); for (int i = 0; i < itemHandler.getSlots(); i++) { inventory.setItem(i, itemHandler.getStackInSlot(i)); } Containers.dropContents(this.level, this.worldPosition, inventory); } } When I click on the Block i get the Item back i put in even after logging out and back in. It is only the Renderer that dosen't work. what am I missing here? full source code: https://github.com/TobiasFiller/MiltenMagic
  2. Sometimes the easy answer is the right one thank you good sir
  3. that is good to know, it works when I use a Supplier thanks Is there a way to get a supplier from vanilla MobEffects? because I use the same class with an vanilla mob effect aswell. or should I just write two classes, one for my custom mob effects and one for vanilla mob effects?
  4. I am having Problems using a custom MobEffect in my Item Registry. public static final RegistryObject<Item> MAGNETIC_SCROLL = ITEMS.register("magnetic_scroll", () -> new BuffSpellItem(MobEffectRegistry.MAGNETIC_MOB_EFFECT.get(), 5000, 0, 10, 10)); for some reason I get a null Point Exception although the Mob Effect itself without the Item to use it works fine. Here is the Mob Effect Registry: public class MobEffectRegistry { public static final DeferredRegister<MobEffect> MOB_EFFECT = DeferredRegister.create(ForgeRegistries.MOB_EFFECTS, MiltenMagic.MOD_ID); public static final RegistryObject<MobEffect> MAGNETIC_MOB_EFFECT = MOB_EFFECT.register("magnetic", MagneticMobEffect::new); } do I need to register my Objects in a specific order?
×
×
  • Create New...

Important Information

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