Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

TobiasFiller

Members
  • Joined

  • Last visited

Everything posted by TobiasFiller

  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?

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.