Jump to content

Custom Boat (1.19)


LB2

Recommended Posts

  • 1 month later...

public class ModBoat extends Boat {

private static final EntityDataAccessor<Integer> DATA_ID_TYPE = SynchedEntityData.defineId(Boat.class, EntityDataSerializers.INT);

public ModBoat(EntityType<? extends Boat> p_38290_, Level p_38291_) { super(p_38290_, p_38291_);

}

public ModBoat.Type getModBoatType() { return ModBoat.Type.byId(this.entityData.get(DATA_ID_TYPE)); } public void setType(ModBoat.Type p_38333_) { this.entityData.set(DATA_ID_TYPE, p_38333_.ordinal());

}

public static enum Type {

CHERRY(ModBlocks.CHERRY_PLANKS.get(), "cherry"),

ALMOND(ModBlocks.ALMOND_PLANKS.get(), "almond"),

PEACH(ModBlocks.PEACH_PLANKS.get(), "peach"),

APPLE(ModBlocks.APPLE_PLANKS.get(), "apple"),

PLUM(ModBlocks.PLUM_PLANKS.get(), "plum"),

PEAR(ModBlocks.PEAR_PLANKS.get(), "pear");

private final String name;

private final Block planks;

private Type(Block p_38427_, String p_38428_) { this.name = p_38428_; this.planks = p_38427_;

}

public String getName() { return this.name; }

public Block getPlanks() { return this.planks; }

public String toString() { return this.name; }

public static ModBoat.Type byId(int p_38431_) { ModBoat.Type[] aboat$type = values();

if (p_38431_ < 0 || p_38431_ >= aboat$type.length) {

p_38431_ = 0;

}

return aboat$type[p_38431_]; } } }

----------------------------------------------------------

Thats all I got in this class

Edited by LB2
Link to comment
Share on other sites

8 hours ago, ChampionAsh5357 said:

Ok, what are you doing with it? Where's the renderer and model? Have you registered an entity type? An entity needs those things to be able to function without crashing.

I maded the Boat and the BoatItem classes and it works, but when i spawn the boat the world crashes :(

Edited by LB2
Link to comment
Share on other sites

18 hours ago, ChampionAsh5357 said:

I will repeat the same thing again: Where's the renderer and model? Have you registered an entity type? An entity needs those things to be able to function without crashing.

I registered the Boat and Chest Boat Classes and I registered the entity type and the renderer

Also i have an error when I spawn the boat, the world just crashes.

(Caused by: java.lang.IllegalStateException: Registry is already frozen)

Edited by LB2
Link to comment
Share on other sites

On 5/16/2023 at 6:28 PM, ChampionAsh5357 said:

How are you registering the boat? Because that suggests you're trying to register the boat when it spawns, and not during the registry portion.

I just registered the entity type

Thats the class:

public class ModEntityTypes extends EntityType{

private static final Logger LOGGER = LogUtils.getLogger();

public static final DeferredRegister<EntityType<?>> MOD_ENTITY_TYPES = DeferredRegister.create(ForgeRegistries.ENTITIES, Foodstuffs.MOD_ID);

public static final EntityType<ModBoat> MOD_BOAT = register("mod_boat", ModEntityTypes.Builder.<ModBoat>of(ModBoat::new, MobCategory.MISC).sized(1.375F, 0.5625F).clientTrackingRange(10));

public static final EntityType<ModChestBoat> MOD_CHEST_BOAT = register("mod_chest_boat", ModEntityTypes.Builder.<ModChestBoat>of(ModChestBoat::new, MobCategory.MISC).sized(1.375F, 0.5625F).clientTrackingRange(10));

public ModEntityTypes(EntityFactory p_20574_, MobCategory p_20575_, boolean p_20576_, boolean p_20577_, boolean p_20578_, boolean p_20579_, ImmutableSet p_20580_, EntityDimensions p_20581_, int p_20582_, int p_20583_) { super(p_20574_, p_20575_, p_20576_, p_20577_, p_20578_, p_20579_, p_20580_, p_20581_, p_20582_, p_20583_);

}

private static <T extends Entity> EntityType<T> register(String p_20635_, ModEntityTypes.Builder<T> p_20636_) { return Registry.register(Registry.ENTITY_TYPE, p_20635_, p_20636_.build(p_20635_));

}

public static void register(IEventBus eventBus) { MOD_ENTITY_TYPES.register(eventBus);

        }

}

Link to comment
Share on other sites

https://docs.minecraftforge.net/en/latest/concepts/registries/

or https://forge.gemwire.uk/wiki/Registration#DeferredRegister

 

You can't register objects directly with the registries, except during the RegisterEvent when the registries are unfrozen.

You are trying to do it during classloading/static initialisation which occurs at an "unknown time", almost certainly when the registries are frozen.

A RegistryObject (which is the recommended mechanism) will do the registration for you at the correct time.

 

In future if you want help, put a minimal project on github that reproduces your problem so we can see everything you are doing.

Posting badly formatted and incomplete code in the forums will likely just mean your question gets ignored. Unless it is obvious what the problem is from what little information you post.

Edited by warjort

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

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

    • They were already updated, and just to double check I even did a cleanup and fresh update from that same page. I'm quite sure drivers are not the problem here. 
    • 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;     }  
  • Topics

×
×
  • Create New...

Important Information

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