Jump to content

TE hasn't been registered


dyno

Recommended Posts

I cannot understand what i am doing wrong.

It seems like forge never register TE: I tried to use an item to know if its TE has been registered. It says that it hasn't any TE

 

Block:

package com.olivemod.blocks.machine.energy_cell.copper;

import com.olivemod.utils.ModTileEntityTypes;
import com.olivemod.utils.Reference.NBTKeys;
import com.olivemod.utils.Reference.Reference;

import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.ContainerBlock;
import net.minecraft.block.RedstoneTorchBlock;
import net.minecraft.block.material.Material;
import net.minecraft.entity.LivingEntity;
import net.minecraft.item.BlockItemUseContext;
import net.minecraft.item.ItemStack;
import net.minecraft.state.BooleanProperty;
import net.minecraft.state.StateContainer.Builder;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.Direction;
import net.minecraft.util.Hand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockReader;
import net.minecraft.world.IWorld;
import net.minecraft.world.World;
import net.minecraftforge.common.ToolType;
import net.minecraftforge.energy.CapabilityEnergy;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventBusSubscriber;

public class CopperCell extends Block{
	
	private static BooleanProperty energyIn = BooleanProperty.create("lit");

	public CopperCell() {
		
		super(Properties.create(Material.IRON).hardnessAndResistance(5.0f).harvestTool(ToolType.PICKAXE));
		this.setDefaultState(this.getDefaultState().with(energyIn, Boolean.valueOf(false)));
	}

	@Override
	public BlockState getStateForPlacement(BlockItemUseContext context) {

		return this.getDefaultState().with(energyIn, Boolean.valueOf(false));
	}

	@Override
	public boolean hasTileEntity() {

		return true;
	}
	
	@Override
	public TileEntity createTileEntity(BlockState state, IBlockReader world) {

		return ModTileEntityTypes.COPPER_CELL_TE.get().create();
	}
	
	@Override
	protected void fillStateContainer(Builder<Block, BlockState> builder) {

		builder.add(energyIn);
	}
	
	
	

}

TE:

package com.olivemod.blocks.machine.energy_cell.copper;

import javax.annotation.Nonnull;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.core.Logger;

import com.olivemod.blocks.transfer.energy.CableType;
import com.olivemod.energy.SeattableEnergyStorage.SettableEnergyStorage;
import com.olivemod.utils.ModTileEntityTypes;
import com.olivemod.utils.ModUtils;
import com.olivemod.utils.Reference.NBTKeys;
import com.sun.istack.internal.Nullable;
import net.minecraft.client.renderer.texture.ITickable;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.network.NetworkManager;
import net.minecraft.network.play.server.SUpdateTileEntityPacket;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityType;
import net.minecraft.util.Direction;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.util.LazyOptional;
import net.minecraftforge.energy.CapabilityEnergy;
import net.minecraftforge.energy.IEnergyStorage;

public class CopperEnergyCellTE extends TileEntity implements ITickable{

	private static final int capacity = 2500;
	private static final int maxTransfer = 100;
	public final SettableEnergyStorage storage = new SettableEnergyStorage(capacity, maxTransfer);
	private final LazyOptional<IEnergyStorage> energyLazyOptional = LazyOptional.of( () -> this.storage);
	private int lastEnergy = -1;
	
	public CopperEnergyCellTE() {

		super(ModTileEntityTypes.COPPER_CELL_TE.get());
	}
	
	public CopperEnergyCellTE(TileEntityType<?> tileEntityTypeIn) {
		super(tileEntityTypeIn);
	}
	
	@Override
	public void tick() {

		transferEnergy(capacity, maxTransfer);
	}
	
	private void transferEnergy(int capacity, int maxTransfer) {
		
		for (Direction direction : ModUtils.DIRECTIONS) 
		{
			IEnergyStorage storage = world.getTileEntity(pos.offset(direction)).getCapability(CapabilityEnergy.ENERGY).orElse(null);
			if(storage != null && storage.getEnergyStored() < storage.getMaxEnergyStored() && storage.canReceive())
			{
				storage.receiveEnergy(this.storage.extractEnergy(maxTransfer, false), false);
			}
			if(storage != null && storage.getEnergyStored() > 0 && storage.canExtract())
			{
				this.storage.addEnergy(storage.extractEnergy(maxTransfer, false));
			}
			//let vanilla update chunk
			this.markDirty();	
			//Notify client of a block update
			//This will result in the packet from getUpdatePacket beong sent to the client
			//Energy will be synced
			//Flag 2 send change to client
			world.notifyBlockUpdate(pos, this.getBlockState(), this.getBlockState(), 2);
			this.lastEnergy = storage.getEnergyStored();
		}
		
	}
	
	@Override
	public void onDataPacket(NetworkManager net, SUpdateTileEntityPacket pkt) {

		this.storage.setEnergy(pkt.getNbtCompound().getInt(NBTKeys.ENERGY.getKey()));
	}

	@Override
	public CompoundNBT write(CompoundNBT compound) {

		super.write(compound);
		compound.putInt(NBTKeys.ENERGY.getKey(), this.storage.getEnergyStored());
		
		return compound;
	}
	
	@Override
	public void read(CompoundNBT compound) {

		super.read(compound);
		this.storage.setEnergy(compound.getInt(NBTKeys.ENERGY.getKey()));
	}
	
	@Override
	public <T> LazyOptional<T> getCapability(Capability<T> cap) {

		if(cap == CapabilityEnergy.ENERGY)
		{
			return this.energyLazyOptional.cast();
			
		}
		return null;
	}

	@Override
	public void onLoad() {

		if(!world.isRemote && world != null)
			this.lastEnergy = getCapability(CapabilityEnergy.ENERGY).orElse(null).getEnergyStored();
	}
	
	/*
	 * Retrieves packet to send to the client whenever this Tile Entity is re-sinced via World#notifyBlockUpdate. 
	 * This packet comes back client-side via (@link #onDataPacket)
	 */
	@Nullable
	@Override
	public SUpdateTileEntityPacket getUpdatePacket() {

		final CompoundNBT tag = new CompoundNBT();
		if(tag.contains(NBTKeys.ENERGY.getKey()))
			tag.putInt(NBTKeys.ENERGY.getKey(), this.storage.getEnergyStored());
		//We pass 0 for TileEntityTypesIn because we have a modded TE.See ClientPlayNetHandler#handlerUpdateTileEntity(SUpdateTileEntityPacket)
		return new SUpdateTileEntityPacket(this.pos, 0, tag);
	}
	
	
	/*
	 * Get an NBT compount to sync to the client with SPacketChunkData, used to initial loading of the chunk or when many blocks change at once
	 * This compound comes back to the client-side in (@link #handleUpdateTag)
	 * The default implementation ({@link TileEntity#handleUpdateTag}) calls {@link #writeInternal)}
	 * wich doesn't save any of our extra data so we override it to call {@link #write} instead 
	 */
	@Nonnull
	public CompoundNBT getUpdateTag() {

		return this.write(new CompoundNBT());
	}
}

ModTileEntityTypes:

package com.olivemod.utils;

import javax.annotation.Nonnull;

import com.olivemod.blocks.cable.energy.CopperCableTE;
import com.olivemod.blocks.machine.energy.crusher.TileEntityCrusher;
import com.olivemod.blocks.machine.energy.electric_furnace.TileEntityElectricFurnace;
import com.olivemod.blocks.machine.energy.generator.glowstone_generator.TileEntityGlowStoneGenerator;
import com.olivemod.blocks.machine.energy_cell.copper.CopperEnergyCellTE;
import com.olivemod.blocks.transfer.energy.EnergyCableTileEntity;
import com.olivemod.init.BlockInit;
import com.olivemod.utils.Reference.Reference;
import net.minecraft.tileentity.TileEntityType;
import net.minecraftforge.fml.RegistryObject;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;

public class ModTileEntityTypes {

	//HERE YOU REGISTER YOUR TEs
	
	public static final DeferredRegister<TileEntityType<?>> TILE_ENTITY_TYPE = new DeferredRegister<>(ForgeRegistries.TILE_ENTITIES, Reference.MOD_ID);
	
	public static final RegistryObject<TileEntityType<TileEntityGlowStoneGenerator>> GLOWSTONE_GENERATOR_TE = 
			TILE_ENTITY_TYPE.register("glowstone_generator", () -> TileEntityType.Builder.create(TileEntityGlowStoneGenerator::new, BlockInit.GLOWSTONE_GENERATOR.get()).build(null));

	public static final RegistryObject<TileEntityType<TileEntityElectricFurnace>> ELECTRIC_FURNACE_TE = 
			TILE_ENTITY_TYPE.register("electric_furnace", () -> TileEntityType.Builder.create(TileEntityElectricFurnace::new, BlockInit.ELECTRIC_FURNACE.get()).build(null));

	public static final RegistryObject<TileEntityType<TileEntityCrusher>> CRUSHER_TE = 
			TILE_ENTITY_TYPE.register("crusher", () -> TileEntityType.Builder.create(TileEntityCrusher::new,  BlockInit.CRUSHER.get()).build(null));
	
	public static final RegistryObject<TileEntityType<CopperEnergyCellTE>> COPPER_CELL_TE = 
			TILE_ENTITY_TYPE.register("copper_cell", () -> TileEntityType.Builder.create(CopperEnergyCellTE::new, BlockInit.COPPER_ENERGY_CELL.get()).build(null));
	
	public static final RegistryObject<TileEntityType<CopperCableTE>> COPPER_CABLE_TE = 
			TILE_ENTITY_TYPE.register("copper_cable", () -> TileEntityType.Builder.create(CopperCableTE::new, BlockInit.COPPER_CABLE.get()).build(null));
	
	/*public static final RegistryObject<TileEntityType<GoldCableTE>> GOLD_CABLE_TE = 
			TILE_ENTITY_TYPE.register("gold_cable", () -> TileEntityType.Builder.create(GoldCableTE::new, BlockInit.COPPER_CABLE.get()).build(null));
	
	public static final RegistryObject<TileEntityType<RedstoneCableTE>> REDSTONE_CABLE_TE = 
			TILE_ENTITY_TYPE.register("redstone_cable", () -> TileEntityType.Builder.create(RedstoneCableTE::new, BlockInit.COPPER_CABLE.get()).build(null));
*/
	
}

 

2020-05-31_21.19.17.png

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

    • i tried downloading the drivers but it says no AMD graphics hardware has been detected    
    • Update your AMD/ATI drivers - get the drivers from their website - do not update via system  
    • As the title says i keep on crashing on forge 1.20.1 even without any mods downloaded, i have the latest drivers (nvidia) and vanilla minecraft works perfectly fine for me logs: https://pastebin.com/5UR01yG9
    • Hello everyone, I'm making this post to seek help for my modded block, It's a special block called FrozenBlock supposed to take the place of an old block, then after a set amount of ticks, it's supposed to revert its Block State, Entity, data... to the old block like this :  The problem I have is that the system breaks when handling multi blocks (I tried some fix but none of them worked) :  The bug I have identified is that the function "setOldBlockFields" in the item's "setFrozenBlock" function gets called once for the 1st block of multiblock getting frozen (as it should), but gets called a second time BEFORE creating the first FrozenBlock with the data of the 1st block, hence giving the same data to the two FrozenBlock :   Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=head] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@73681674 BlockEntityData : id:"minecraft:bed",x:3,y:-60,z:-6} Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=3, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=2, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} here is the code inside my custom "freeze" item :    @Override     public @NotNull InteractionResult useOn(@NotNull UseOnContext pContext) {         if (!pContext.getLevel().isClientSide() && pContext.getHand() == InteractionHand.MAIN_HAND) {             BlockPos blockPos = pContext.getClickedPos();             BlockPos secondBlockPos = getMultiblockPos(blockPos, pContext.getLevel().getBlockState(blockPos));             if (secondBlockPos != null) {                 createFrozenBlock(pContext, secondBlockPos);             }             createFrozenBlock(pContext, blockPos);             return InteractionResult.SUCCESS;         }         return super.useOn(pContext);     }     public static void createFrozenBlock(UseOnContext pContext, BlockPos blockPos) {         BlockState oldState = pContext.getLevel().getBlockState(blockPos);         BlockEntity oldBlockEntity = oldState.hasBlockEntity() ? pContext.getLevel().getBlockEntity(blockPos) : null;         CompoundTag oldBlockEntityData = oldState.hasBlockEntity() ? oldBlockEntity.serializeNBT() : null;         if (oldBlockEntity != null) {             pContext.getLevel().removeBlockEntity(blockPos);         }         BlockState FrozenBlock = setFrozenBlock(oldState, oldBlockEntity, oldBlockEntityData);         pContext.getLevel().setBlockAndUpdate(blockPos, FrozenBlock);     }     public static BlockState setFrozenBlock(BlockState blockState, @Nullable BlockEntity blockEntity, @Nullable CompoundTag blockEntityData) {         BlockState FrozenBlock = BlockRegister.FROZEN_BLOCK.get().defaultBlockState();         ((FrozenBlock) FrozenBlock.getBlock()).setOldBlockFields(blockState, blockEntity, blockEntityData);         return FrozenBlock;     }  
    • It is an issue with quark - update it to this build: https://www.curseforge.com/minecraft/mc-mods/quark/files/3642325
  • Topics

×
×
  • Create New...

Important Information

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