Jump to content

[1.19] Tick method not working


toocrazy

Recommended Posts

Hey,

I use a ticker in one of my Blockentites and it works completely fine:

BlockEntity: (working)

Spoiler
package de.toocrazy.reddeathmod.block.blocks.entity.Custom;

import com.mojang.blaze3d.vertex.BufferBuilder;
import com.mojang.blaze3d.vertex.PoseStack;
import de.toocrazy.reddeathmod.block.blocks.TimeExtractorBlock;
import de.toocrazy.reddeathmod.block.blocks.entity.ModBlockEntities;
import de.toocrazy.reddeathmod.item.ModItems;
import de.toocrazy.reddeathmod.screen.TimeExtractorMenu;
import net.minecraft.advancements.CriteriaTriggers;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.blockentity.BeaconRenderer;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.particles.ParticleOptions;
import net.minecraft.core.particles.ParticleType;
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.util.RandomSource;
import net.minecraft.world.Containers;
import net.minecraft.world.MenuProvider;
import net.minecraft.world.SimpleContainer;
import net.minecraft.world.entity.item.ItemEntity;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.util.LazyOptional;
import net.minecraftforge.items.CapabilityItemHandler;
import net.minecraftforge.items.ItemStackHandler;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import javax.annotation.Nonnull;

public class TimeExtractorBlockEntity extends BlockEntity implements MenuProvider {


    private final ItemStackHandler itemHandler = new ItemStackHandler(3) {
        @Override
        protected void onContentsChanged(int slot) {
            setChanged();
        }
    };

    private LazyOptional<ItemStackHandler> lazyItemHandler = LazyOptional.empty();

    public TimeExtractorBlockEntity(BlockPos p_155229_, BlockState p_155230_) {
        super(ModBlockEntities.TIME_EXTRACTOR_ENTITY.get(), p_155229_, p_155230_);
    }

    @Override
    public Component getDisplayName() {
        return Component.literal("Time Reverter");
    }

    @Nullable
    @Override
    public AbstractContainerMenu createMenu(int containerId, Inventory inv, Player player) {
        return new TimeExtractorMenu(containerId, inv, this);
    }
    @Nonnull
    @Override
    public <T> LazyOptional<T> getCapability(@Nonnull Capability<T> cap, @javax.annotation.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(@NotNull CompoundTag tag) {
        tag.put("inventory", itemHandler.serializeNBT());
        super.saveAdditional(tag);
    }

    @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);
    }


    public static void tick(Level pLevel, BlockPos pPos, BlockState pState, TimeExtractorBlockEntity pBlockEntity) {
        updateState(pLevel,pPos,pState,pBlockEntity);
        if(hasRecipe(pBlockEntity) && hasNotReachedStackLimit(pBlockEntity)) {
            craftItem(pBlockEntity);
        }


        // TODO BeaconRenderer.renderBeaconBeam(new PoseStack(), MultiBufferSource.immediate(new BufferBuilder(30)),BEAM_LOCATION, 5, 5, 5, 5, 5,new float[5], 5, 5);

        pLevel.addParticle(ParticleTypes.FIREWORK,
                pPos.getX()+0.5,
                pPos.getY()+0.5+1.5,
                pPos.getZ()-2.5,
                0,
                0.1,
                0.28);
        pLevel.addParticle(ParticleTypes.FIREWORK,
                pPos.getX()-2.5,
                pPos.getY()+0.5+1.5,
                pPos.getZ()+0.5,
                0.28,
                0.1,
                0);
        pLevel.addParticle(ParticleTypes.FIREWORK,
                pPos.getX()+3.5,
                pPos.getY()+0.5+1.5,
                pPos.getZ()+0.5,
                -0.28,
                0.1,
                0);
        pLevel.addParticle(ParticleTypes.FIREWORK,
                pPos.getX()+0.5,
                pPos.getY()+0.5+1.5,
                pPos.getZ()+3.5,
                0,
                0.1,
                -0.28);

        pLevel.addParticle(ParticleTypes.CRIMSON_SPORE,
                pPos.getX()+0.5,
                pPos.getY()+0.5+1.5,
                pPos.getZ()+0.5,
                0.1,
                2,
                0);
    }

    private static void updateState(Level level, BlockPos pPos, BlockState pState, TimeExtractorBlockEntity entity) {
       if (entity.itemHandler.getStackInSlot(1).getItem() == ModItems.GRAND_CLOCK.get()) {

           if(!pState.getValue(TimeExtractorBlock.CLOCK)) {
               level.setBlock(pPos, pState.setValue(TimeExtractorBlock.CLOCK, true), 3);


           }
       } else {
           if(pState.getValue(TimeExtractorBlock.CLOCK)) {
               level.setBlock(pPos, pState.setValue(TimeExtractorBlock.CLOCK, false), 3);
           }
       }
    }

    private static void craftItem(TimeExtractorBlockEntity entity) {
        entity.itemHandler.extractItem(0, 1, false);
        entity.itemHandler.getStackInSlot(1).setDamageValue(entity.itemHandler.getStackInSlot(1).getDamageValue() - 1000);
        entity.itemHandler.setStackInSlot(2, new ItemStack(Items.ROTTEN_FLESH,
                entity.itemHandler.getStackInSlot(2).getCount() + 1));
    }

    private static boolean hasRecipe(TimeExtractorBlockEntity entity) {
        boolean hasItemInFirstSlot = entity.itemHandler.getStackInSlot(0).getItem() == Items.BEEF;
        boolean hasClock = entity.itemHandler.getStackInSlot(1).getItem() == ModItems.GRAND_CLOCK.get();

        return hasItemInFirstSlot && hasClock;
    }

    private static boolean hasNotReachedStackLimit(TimeExtractorBlockEntity entity) {
        return entity.itemHandler.getStackInSlot(2).getCount() < entity.itemHandler.getStackInSlot(2).getMaxStackSize();
    }
}

 

  Block: (working)

Spoiler
package de.toocrazy.reddeathmod.block.blocks;



import de.toocrazy.reddeathmod.block.blocks.entity.Custom.TimeExtractorBlockEntity;
import de.toocrazy.reddeathmod.block.blocks.entity.ModBlockEntities;
import de.toocrazy.reddeathmod.item.ModItems;

import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.item.ItemEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.context.BlockPlaceContext;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.*;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityTicker;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.block.state.properties.BooleanProperty;
import net.minecraft.world.level.block.state.properties.DirectionProperty;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraftforge.network.NetworkHooks;
import org.jetbrains.annotations.Nullable;

public class TimeExtractorBlock extends BaseEntityBlock {
    public static final DirectionProperty FACING = HorizontalDirectionalBlock.FACING;
    public static final BooleanProperty CLOCK = BooleanProperty.create("clock");


    public TimeExtractorBlock(Properties properties) {
        super(properties);
        this.registerDefaultState(this.stateDefinition.any().setValue(FACING, Direction.NORTH).setValue(CLOCK, Boolean.valueOf(false)));

    }


    //FACING//

    @Override
    public BlockState getStateForPlacement(BlockPlaceContext context) {
        return this.defaultBlockState().setValue(FACING, context.getHorizontalDirection().getOpposite());
    }

    @Override
    public BlockState rotate(BlockState p_48722_, Rotation p_48723_) {
        return p_48722_.setValue(FACING, p_48723_.rotate(p_48722_.getValue(FACING)));
    }

    @Override
    public BlockState mirror(BlockState p_48719_, Mirror p_48720_) {
        return p_48719_.rotate(p_48720_.getRotation(p_48719_.getValue(FACING)));
    }

    @Override
    protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> p_48725_) {
        p_48725_.add(FACING, CLOCK);
    }

    //BLOCK ENTITY
    @Override
    public RenderShape getRenderShape(BlockState pState) {
        return RenderShape.MODEL;
    }


    @Override
    public void onRemove(BlockState pState, Level pLevel, BlockPos pPos, BlockState pNewState, boolean pIsMoving) {
        if (pState.getBlock() != pNewState.getBlock()) {
            BlockEntity blockEntity = pLevel.getBlockEntity(pPos);
            if (blockEntity instanceof TimeExtractorBlockEntity) {
                ((TimeExtractorBlockEntity) blockEntity).drops();
            }
        }
        super.onRemove(pState, pLevel, pPos, pNewState, pIsMoving);
    }

    @Override
    public InteractionResult use(BlockState pState, Level pLevel, BlockPos pPos,
                                 Player pPlayer, InteractionHand pHand, BlockHitResult pHit) {

        if (!pLevel.isClientSide() && !pPlayer.isShiftKeyDown() ) {
            BlockEntity entity = pLevel.getBlockEntity(pPos);
            System.out.println(entity); //TODO remove
            if(entity instanceof TimeExtractorBlockEntity) {
                NetworkHooks.openScreen(((ServerPlayer)pPlayer), (TimeExtractorBlockEntity)entity, pPos);
            } else {
                throw new IllegalStateException("Our Container provider is missing!");
            }
        }

        ItemEntity item = new ItemEntity(pLevel, pPos.getX(),pPos.getY()+1,pPos.getZ(), new ItemStack(ModItems.GRAND_CLOCK.get(), 1));
        item.setNeverPickUp();
        item.moveTo(pPos.offset(0,1,0),0,0);
        item.lifespan = 50; //TODO remove-added for debuging
        item.setDeltaMovement(0,0,0);
        item.setGlowingTag(true);
        pLevel.addFreshEntity(item);

        return InteractionResult.sidedSuccess(pLevel.isClientSide());
    }






    @Nullable
    @Override
    public BlockEntity newBlockEntity(BlockPos pPos, BlockState pState) {
        return new TimeExtractorBlockEntity(pPos, pState);
    }

    @Nullable
    @Override
    public <T extends BlockEntity> BlockEntityTicker<T> getTicker(Level pLevel, BlockState pState, BlockEntityType<T> pBlockEntityType) {
        System.out.println(pBlockEntityType + " equals " + ModBlockEntities.TIME_EXTRACTOR_ENTITY.get());
        return createTickerHelper(pBlockEntityType, ModBlockEntities.TIME_EXTRACTOR_ENTITY.get(),
                TimeExtractorBlockEntity::tick);
    }

}

 

But when trying to use it in a different BlockEntity it somehow doesn't work? (event tho the code of the ticker is nearly identical).

The only real difference is that the "TimeFusor" does not implement "MenueProvider" (tried implementing it already)

BlockEntity: (not working)

Spoiler
package de.toocrazy.reddeathmod.block.blocks.entity.Custom;

import de.toocrazy.reddeathmod.block.blocks.entity.ModBlockEntities;
import net.minecraft.core.BlockPos;
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.Component;
import net.minecraft.world.Containers;
import net.minecraft.world.MenuProvider;
import net.minecraft.world.SimpleContainer;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityTicker;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraftforge.common.util.LazyOptional;
import net.minecraftforge.items.ItemStackHandler;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public class TimeFusorBlockEntity extends BlockEntity {

    private LazyOptional<ItemStackHandler> lazyItemHandler = LazyOptional.empty();
    private boolean fusionActive;

    private final ItemStackHandler itemHandler = new ItemStackHandler(1) {
        @Override
        protected void onContentsChanged(int slot) {
            setChanged();
        }
    };

    public TimeFusorBlockEntity(BlockPos p_155229_, BlockState p_155230_) {
        super(ModBlockEntities.TIME_ALTAR_ENTITY.get(), p_155229_, p_155230_);
    }

    public void setItemStack(TimeFusorBlockEntity entity, ItemStack stack) {
        entity.itemHandler.setStackInSlot(0, stack);
    }

    public ItemStack getItemStack(TimeFusorBlockEntity entity) {
        return entity.itemHandler.getStackInSlot(0);
    }

    public void setFusionActive(TimeFusorBlockEntity entity, boolean fusionActive) {
        entity.fusionActive = fusionActive;
    }

    public boolean isFusionActive(TimeFusorBlockEntity entity) {
        return entity.fusionActive;
    }

    @Override
    public void onLoad() {
        super.onLoad();
        lazyItemHandler = LazyOptional.of(() -> itemHandler);
    }

    @Override
    public void invalidateCaps()  {
        super.invalidateCaps();
        lazyItemHandler.invalidate();
    }

    @Override
    protected void saveAdditional(@NotNull CompoundTag tag) {
        tag.put("inventory", itemHandler.serializeNBT());
        tag.putBoolean("eventActive", fusionActive);
        super.saveAdditional(tag);
    }

    @Override
    public void load(CompoundTag nbt) {
        super.load(nbt);
        itemHandler.deserializeNBT(nbt.getCompound("inventory"));
        fusionActive = nbt.getBoolean("eventActive");
    }

    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);
    }

    public static void tick(Level pLevel, BlockPos pPos, BlockState pState, TimeFusorBlockEntity pBlockEntity) {

        System.out.println("Tick");

    }


}

 

Block: (not working)

Spoiler
package de.toocrazy.reddeathmod.block.blocks;

import com.mojang.blaze3d.vertex.BufferBuilder;
import com.mojang.blaze3d.vertex.PoseStack;
import de.toocrazy.reddeathmod.block.blocks.entity.Custom.TimeAltarBlockEntity;
import de.toocrazy.reddeathmod.block.blocks.entity.Custom.TimeExtractorBlockEntity;
import de.toocrazy.reddeathmod.block.blocks.entity.Custom.TimeFusorBlockEntity;
import de.toocrazy.reddeathmod.block.blocks.entity.ModBlockEntities;
import de.toocrazy.reddeathmod.item.ModItems;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.blockentity.BeaconRenderer;
import net.minecraft.client.renderer.blockentity.BlockEntityRenderer;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.item.ItemEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.item.Tiers;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.BaseEntityBlock;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.RenderShape;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityTicker;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.shapes.BooleanOp;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.Shapes;
import net.minecraft.world.phys.shapes.VoxelShape;
import org.jetbrains.annotations.Nullable;

import java.util.List;
import java.util.stream.Stream;

public class TimeFusor extends BaseEntityBlock   {
    //TODO implements BlockEntityRenderer<TimeFusorBlockEntity>
    public static final ResourceLocation BEAM_LOCATION = new ResourceLocation("textures/entity/beacon_beam.png");

    public TimeFusor(Properties properties) {
        super(properties);
    }

    private final VoxelShape SHAPE =
            Stream.of(
                    Block.box(4, 5, 4, 12, 6, 12),
                    Block.box(0, 5, 0, 3, 13, 3),
                    Block.box(13, 5, 0, 16, 13, 3),
                    Block.box(13, 5, 13, 16, 13, 16),
                    Block.box(0, 5, 13, 3, 13, 16),
                    Block.box(0, 0, 0, 16, 5, 16)
            ).reduce((v1, v2) -> Shapes.joinUnoptimized(v1, v2, BooleanOp.OR)).get();

    // Shapes.joinUnoptimized(Block.box(0, 0, 0, 16, 8, 16), Block.box(5, 8, 5, 11, 9, 11), BooleanOp.OR);

    @Override
    public VoxelShape getShape(BlockState state, BlockGetter getter, BlockPos pos, CollisionContext context) {
        return SHAPE;
    }

    @Override
    public InteractionResult use(BlockState pState, Level pLevel, BlockPos pPos,
                                 Player pPlayer, InteractionHand pHand, BlockHitResult pHit) {
        TimeFusorBlockEntity entity = (TimeFusorBlockEntity) pLevel.getBlockEntity(pPos);
        if (!pLevel.isClientSide()) {

            System.out.println(entity);
            if(entity.getItemStack(entity).getItem() == Items.AIR) {


                ItemEntity itemEntity = new ItemEntity(pLevel, pPos.getX()+0.5,pPos.getY()+0.6,pPos.getZ()+0.5,
                        new ItemStack(pPlayer.getMainHandItem().getItem(), 1));

                entity.setItemStack(entity, pPlayer.getMainHandItem());


                itemEntity.setNeverPickUp();
                itemEntity.lifespan = 1000000000;
                //item.lifespan = 50; //TODO remove-added for debuging
                itemEntity.setDeltaMovement(0,0,0);
                //item.setGlowingTag(true);
                itemEntity.setNoGravity(true);
                pLevel.addFreshEntity(itemEntity);
                System.out.println(entity.getItemStack(entity));

                if(pPlayer.getMainHandItem().getItem() == ModItems.ANCIENT_HAMMER.get()) {
                    initiateFusion(pLevel, pPos, entity, itemEntity);
                }
                pPlayer.setItemSlot(EquipmentSlot.MAINHAND, ItemStack.EMPTY);

            } else {

                System.out.println("EXTRACT: " + entity.getItemStack(entity));
                boolean success = pPlayer.addItem(entity.getItemStack(entity));
                List<Entity> entities = pLevel.getEntities(null, new AABB(pPos));
                for (Entity entity1 : entities) {
                    if(entity1.isNoGravity()) {
                        entity1.kill();
                    }
                }

                entity.setItemStack(entity, ItemStack.EMPTY);
                System.out.println("Extraction was " + success);
            }
        }

        return InteractionResult.sidedSuccess(pLevel.isClientSide());
    }

    public void initiateFusion(Level pLevel, BlockPos pPos, TimeFusorBlockEntity entity, ItemEntity input) {
        if (pLevel.getBlockEntity(pPos.offset(3,0,0)) instanceof TimeAltarBlockEntity &&
                pLevel.getBlockEntity(pPos.offset(0,0,3)) instanceof TimeAltarBlockEntity &&
                pLevel.getBlockEntity(pPos.offset(-3,0,0)) instanceof TimeAltarBlockEntity &&
                pLevel.getBlockEntity(pPos.offset(0,0,-3)) instanceof TimeAltarBlockEntity) {
            TimeAltarBlockEntity block1 = (TimeAltarBlockEntity) pLevel.getBlockEntity(pPos.offset(3,0,0));
            TimeAltarBlockEntity block2 = (TimeAltarBlockEntity) pLevel.getBlockEntity(pPos.offset(0,0,3));
            TimeAltarBlockEntity block3 = (TimeAltarBlockEntity) pLevel.getBlockEntity(pPos.offset(-3,0,0));
            TimeAltarBlockEntity block4 = (TimeAltarBlockEntity) pLevel.getBlockEntity(pPos.offset(0,0,-3));
            if (block1.getItemStack(block1).getItem() == ModItems.GRAND_CLOCK.get() &&
                    block2.getItemStack(block2).getItem() == ModItems.GRAND_CLOCK.get() &&
                    block3.getItemStack(block3).getItem() == ModItems.GRAND_CLOCK.get() &&
                    block4.getItemStack(block4).getItem() == ModItems.GRAND_CLOCK.get()) {
                ItemStack item1 = block1.getItemStack(block1);
                ItemStack item2 = block2.getItemStack(block2);
                ItemStack item3 = block3.getItemStack(block3);
                ItemStack item4 = block4.getItemStack(block4);
                if (getCharge(item1, item2, item3, item4) >= 15000) {
                    removeCharge(item1, item2, item3, item4, 15000);
                    startFusion(pLevel, pPos, entity,input, new ItemStack(ModItems.DEVILS_HAMMER.get(), 1));

                }
            }
        }
    }

    private void startFusion(Level pLevel, BlockPos pPos, TimeFusorBlockEntity entity,ItemEntity input, ItemStack output) {
        //TODO animation
        entity.setFusionActive(entity, true);
        entity.setItemStack(entity, output);

        List<Entity> entities = pLevel.getEntities(null, new AABB(pPos));
        for (Entity entity1 : entities) {
            if(entity1.isNoGravity()) {
                entity1.kill();
            }
        }

        ItemEntity itemEntity = new ItemEntity(pLevel, pPos.getX()+0.5,pPos.getY()+0.6,pPos.getZ()+0.5, output);
        itemEntity.setNeverPickUp();
        itemEntity.lifespan = 1000000000;
        itemEntity.setDeltaMovement(0,0,0);
        itemEntity.setGlowingTag(true);
        itemEntity.setNoGravity(true);
        pLevel.addFreshEntity(itemEntity);

    }

    private boolean removeCharge(ItemStack item1,@Nullable ItemStack item2,@Nullable ItemStack item3,@Nullable ItemStack item4, int remainingCharge) {
        if(item1 != null) {
            int clock1time = 10000 - item1.getDamageValue();
            if (remainingCharge >= clock1time) {
                remainingCharge = remainingCharge- clock1time;
                item1.setDamageValue(10000);
            } else {
                item1.setDamageValue(item1.getDamageValue() + remainingCharge);
                return true;
            }
        }

        if(item2 != null) {
            int clock2time = 10000 - item2.getDamageValue();
            if (remainingCharge >= clock2time) {
                remainingCharge = remainingCharge- clock2time;
                item2.setDamageValue(10000);
            } else {
                item2.setDamageValue(item2.getDamageValue() + remainingCharge);
                return true;
            }
        }

        if(item3 != null) {
            int clock3time = 10000 - item3.getDamageValue();
            if (remainingCharge >= clock3time) {
                remainingCharge = remainingCharge- clock3time;
                item3.setDamageValue(10000);
            } else {
                item3.setDamageValue(item3.getDamageValue() + remainingCharge);
                return true;
            }
        }

        if(item4 != null) {
            int clock4time = 10000 - item4.getDamageValue();
            if (remainingCharge >= clock4time) {
                remainingCharge = remainingCharge- clock4time;
                item4.setDamageValue(10000);
            } else {
                item4.setDamageValue(item4.getDamageValue() + remainingCharge);
                return true;
            }
        }

        return false;
    }




    private int getCharge(ItemStack item1, ItemStack item2, ItemStack item3, ItemStack item4) {
        return 10000 - item1.getDamageValue()+
                10000 - item2.getDamageValue()+
                10000 - item3.getDamageValue()+
                10000 - item4.getDamageValue();
    }

    @Nullable
    @Override
    public BlockEntity newBlockEntity(BlockPos pos, BlockState state) {
        return new TimeFusorBlockEntity(pos, state);
    }

    @Override
    public RenderShape getRenderShape(BlockState pState) {
        return RenderShape.MODEL;
    }

    @Override
    public void onRemove(BlockState pState, Level pLevel, BlockPos pPos, BlockState pNewState, boolean pIsMoving) {
        if (pState.getBlock() != pNewState.getBlock()) {
            BlockEntity blockEntity = pLevel.getBlockEntity(pPos);
            if (blockEntity instanceof TimeFusorBlockEntity) {
                ((TimeFusorBlockEntity) blockEntity).drops();
                List<Entity> entities = pLevel.getEntities(null, new AABB(pPos));
                for (Entity entity1 : entities) {
                    if(entity1.isNoGravity()) {
                        entity1.kill();
                    }
                }
            }
        }
        super.onRemove(pState, pLevel, pPos, pNewState, pIsMoving);
    }

    // TODO @Override
    public void render(TimeFusorBlockEntity entity, float p_112308_, PoseStack poseStack, MultiBufferSource buffer, int p_112311_, int p_112312_) {
        BeaconRenderer.renderBeaconBeam(poseStack, buffer, BEAM_LOCATION, 1.0F, 1, 1000000, 0, 5,new float[]{0,0,0}, 0.2F, 0.25F);
        System.out.println("BEAMRENDER");
    }

    @Nullable
    @Override
    public <T extends BlockEntity> BlockEntityTicker<T> getTicker(Level pLevel, BlockState pState, BlockEntityType<T> pBlockEntityType) {
        System.out.println(pBlockEntityType + " equals " + ModBlockEntities.TIME_FUSOR_ENTITY.get());
        return createTickerHelper(pBlockEntityType, ModBlockEntities.TIME_FUSOR_ENTITY.get(),
                TimeFusorBlockEntity::tick);
    }


}

 

I would appreciate if anyone has atleast an idea why this isn't working as I tried to solve this problem for a few hours already now and I really need that tick funktion for a particle animation.

Thanks in advance ^^

Link to comment
Share on other sites

I would guess you have the wrong BlockEntityType?

Quote

public TimeFusorBlockEntity(BlockPos p_155229_, BlockState p_155230_)  {

    super(ModBlockEntities.TIME_ALTAR_ENTITY.get(), p_155229_, p_155230_);

}

return createTickerHelper(pBlockEntityType, ModBlockEntities.TIME_FUSOR_ENTITY.get()

 

Unrelated: You should never be referencing client specific classes from com.mojang.blaze3d.* or net.minecraft.client.* in common classes (i.e. classes that get loaded on the dedicated server). https://forge.gemwire.uk/wiki/Sides

 

  • Thanks 1

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

Link to comment
Share on other sites

40 minutes ago, warjort said:

 

 

Unrelated: You should never be referencing client specific classes from com.mojang.blaze3d.* or net.minecraft.client.* in common classes (i.e. classes that get loaded on the dedicated server). https://forge.gemwire.uk/wiki/Sides

 

Tysm, it works now as intendet! (kinda embarrasing mistake tho).

You probably mean all the unused imports and the not used render method in TimeFusor.class which I tested to realise they wont work probably and I just didn't remove yet (which I will do now ^^). 

Edited by toocrazy
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • when I just started up the game, I had this one splash on the menu. then I joined a world. I left. but when I exited the world to menu, it said the exact same splash it showed that I started up the game! 😠 and it won't change until I restart the whole game all over again. and I am using my custom splash texture pack, but it was not like that before even when I had it enabled. ugh! what even am I doing wrong? my whole game is ruined!! https://mclo.gs/LRDITtP
    • before I updated my pack I made for paintings++ mod, i noticed and saw that only modded paintings and vanilla ones move one block each time I re-enter my world! is there something wrong? what the hell is even going on? why is there a ghost living in my house?! the modded paintings even phase through blocks which is super weird!! help! here is my painting mod list: Paintings++ Dark paintings Macaw's paintings Joy of painting Immersive paintings My custom paintings++ resource pack
    • Error: java.lang.NullPointerException: Cannot invoke "me.codexadrian.tempad.TempadClientConfig.renderBlur()" because the return value of "me.codexadrian.tempad.TempadClient.getClientConfig()" is null I keep having this error while trying to launch a modpack through the forge modloader, any suggestions? https://docs.google.com/document/d/1CRKUoSiu2e_mDvDTVYpIA5wqD3w-BsCycxBu1_vQ4OA/edit?usp=sharing Crash Report ^^^^
    • I'm trying to start a server with the latest installer, but running the run.bat file doesn't generate new files. It shows the following in the cmd prompt.
    • One of my players is suddenly unable to join a locally hosted MC Eternal server. We have been playing on this server for about 2-3 weeks now. I have tried erasing his player files and his reputation file, and now it just coughs up this and kicks him out: [User Authenticator #5/INFO] [minecraft/NetHandlerLoginServer]: UUID of player EthosTheGod is 7692d8db-02c3-424f-a4ab-0e4e259b106b [20:25:36] [User Authenticator #4/INFO] [minecraft/NetHandlerLoginServer]: UUID of player EthosTheGod is 7692d8db-02c3-424f-a4ab-0e4e259b106b [20:29:35] [Server thread/WARN] [minecraft/MinecraftServer]: Can't keep up! Did the system time change, or is the server overloaded? Running 575849ms behind, skipping 11516 tick(s) [20:29:35] [Server thread/INFO] [minecraft/NetHandlerLoginServer]: com.mojang.authlib.GameProfile@4a6c63f1[id=7692d8db-02c3-424f-a4ab-0e4e259b106b,name=EthosTheGod,properties={textures=[com.mojang.authlib.properties.Property@241ea89e]},legacy=false] (/IP.ADDRESS) lost connection: Disconnected [20:29:35] [Server thread/INFO] [minecraft/NetHandlerLoginServer]: com.mojang.authlib.GameProfile@6ab6c661[id=7692d8db-02c3-424f-a4ab-0e4e259b106b,name=EthosTheGod,properties={textures=[com.mojang.authlib.properties.Property@7f19aae3]},legacy=false] (/IP.ADDRESS) lost connection: Disconnected It just says "connection timed out" on his end. Any ideas?
  • Topics

×
×
  • Create New...

Important Information

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