Jump to content

[1.15.1] How to make a custom entity?


DragonITA

Recommended Posts

Hi, sorry for this late reply! I dont know exactly how to Java syntax work if a error was found. Lua Syntax will stop the script (here it is the .class or the .java) if a error was found then the code dont continue and i muss rerun the script in eclipse. This take some time. Ok, why i say this? I say this then i have a Problem with my custom BlockItem. I want first resolve this Problem and then show the code.

P.S.: I need a little bit of time to refind the code.

Edit: Resolved

Edited by DragonITA
P.S.

New in Modding? == Still learning!

Link to comment
Share on other sites

3 hours ago, DragonITA said:

Hi, sorry for this late reply! I dont know exactly how to Java syntax work if a error was found. Lua Syntax will stop the script (here it is the .class or the .java) if a error was found then the code dont continue and i muss rerun the script in eclipse. This take some time. Ok, why i say this? I say this then i have a Problem with my custom BlockItem. I want first resolve this Problem and then show the code.

P.S.: I need a little bit of time to refind the code.

Java is a static language. It has to compile before running. There must be no syntax errors.

However, it sounds like you are struggling with basic Java syntax. Please learn Java before making a mod, as not knowing Java will cause unnecessary confusions.

  • Like 1

Some tips:

Spoiler

Modder Support:

Spoiler

1. Do not follow tutorials on YouTube, especially TechnoVision (previously called Loremaster) and HarryTalks, due to their promotion of bad practice and usage of outdated code.

2. Always post your code.

3. Never copy and paste code. You won't learn anything from doing that.

4. 

Quote

Programming via Eclipse's hotfixes will get you nowhere

5. Learn to use your IDE, especially the debugger.

6.

Quote

The "picture that's worth 1000 words" only works if there's an obvious problem or a freehand red circle around it.

Support & Bug Reports:

Spoiler

1. Read the EAQ before asking for help. Remember to provide the appropriate log(s).

2. Versions below 1.11 are no longer supported due to their age. Update to a modern version of Minecraft to receive support.

 

 

Link to comment
Share on other sites

Thanks, i am trying to learn Java. I know a little bit the Heritage of the Java syntax. Here is on how i actualy make my entity (i have tried to find the Init Folder in the Vanilla Code to see hoz i should register my entities, but i cant find it. So I tried to watch a video of HarryTalks with version 1.14.4 to go further. But I get an error, have tried to solve it with my current knowledge, but I can't get it right.) Here is my current Code:

 

package mod.dragonita.fantasymod.entities;

import mod.dragonita.fantasymod.init.FantasyModEntities;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.entity.ai.goal.LookAtGoal;
import net.minecraft.entity.ai.goal.LookRandomlyGoal;
import net.minecraft.entity.ai.goal.PanicGoal;
import net.minecraft.entity.ai.goal.WaterAvoidingRandomWalkingGoal;
import net.minecraft.entity.passive.horse.HorseEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.world.World;

public class UnicornEntity extends HorseEntity{
	
	@SuppressWarnings("unchecked")
	public UnicornEntity(EntityType<? extends HorseEntity> type, World worldIn) {
		super((EntityType<? extends HorseEntity>) FantasyModEntities.UNICORN_ENTITY, worldIn);
	}

	protected void registerGoals()
	{
		this.goalSelector.addGoal(1, new PanicGoal(this, 1.2D));
		this.goalSelector.addGoal(6, new WaterAvoidingRandomWalkingGoal(this, 0.7D));
		this.goalSelector.addGoal(7, new LookAtGoal(this, PlayerEntity.class, 6.0F));
		this.goalSelector.addGoal(8, new LookRandomlyGoal(this));
	}
	
	protected void registerAttributes()
	{
		super.registerAttributes();
		this.getAttribute(SharedMonsterAttributes.MAX_HEALTH).setBaseValue(10.0d);
		this.getAttribute(SharedMonsterAttributes.MOVEMENT_SPEED).setBaseValue(5.0d);
	}
}

 

package mod.dragonita.fantasymod.init;

import mod.dragonita.fantasymod.Main;
import mod.dragonita.fantasymod.entities.UnicornEntity;
import net.minecraft.entity.EntityClassification;
import net.minecraft.entity.EntityType;
import net.minecraft.item.Item;
import net.minecraft.item.SpawnEggItem;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.biome.Biomes;
import net.minecraft.world.biome.Biome.SpawnListEntry;
import net.minecraftforge.event.RegistryEvent;

public class FantasyModEntities {
	
	public static EntityType<?> UNICORN_ENTITY = EntityType.Builder.create(UnicornEntity::new, EntityClassification.CREATURE).build(Main.MODID + ":unicorn_entity").setRegistryName(new ResourceLocation(Main.MODID, "unicorn_entity"));
	
	public static void registerEntitySpawnEggs(final RegistryEvent.Register<Item> event)
	{
		event.getRegistry().registerAll
		(
			ModItems.UNICORN_ENTITY_EGG = registerEntitySpawnEgg(UNICORN_ENTITY, 0xf0f0f0, 0xdf51f5, "unicorn_entity_egg")	
		);
	}
	
	public static void registerEntityWorldSpawns()
	{
		registerEntityWorldSpawn(UNICORN_ENTITY, Biomes.PLAINS, Biomes.JUNGLE, Biomes.BEACH);
	}
	
	public static Item registerEntitySpawnEgg(EntityType<?> type, int color1, int color2, String name)
	{
		SpawnEggItem item = new SpawnEggItem(type, color1, color2, new Item.Properties().group(ModItemGroups.RAINBOW_MOD_GROUP));
		item.setRegistryName(new ResourceLocation(Main.MODID, name));
		return item;
	}
	
	public static void registerEntityWorldSpawn(EntityType<?> entity, Biome... biomes)
	{
		for(Biome biome : biomes)
		{
			if(biome != null)
			{
				biome.getSpawns(entity.getClassification()).add(new SpawnListEntry(entity, 20, 1, 10));
			}
		}
	}
}

 

 

package mod.dragonita.fantasymod.client.renders;

import mod.dragonita.fantasymod.client.models.UnicornEntityModel;
import mod.dragonita.fantasymod.entities.UnicornEntity;
import net.minecraft.client.renderer.entity.EntityRenderer;
import net.minecraft.client.renderer.entity.EntityRendererManager;
import net.minecraft.client.renderer.entity.LivingRenderer;
import net.minecraft.entity.passive.horse.AbstractHorseEntity;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.fml.client.registry.IRenderFactory;

@OnlyIn(Dist.CLIENT)
public class UnicornEntityRender extends LivingRenderer<AbstractHorseEntity, UnicornEntityModel>
{
	public UnicornEntityRender(EntityRendererManager manager)
	{
		super(manager, new UnicornEntityModel(0f), 0f);
	}

	public static final ResourceLocation unicorn = new ResourceLocation("fantasymod:textures/entity/unicorn_entity.png");
	
	public static class RenderFactory implements IRenderFactory<UnicornEntity>
	{

		@Override
		public EntityRenderer<? super UnicornEntity> createRenderFor(EntityRendererManager manager)
		{
			return new UnicornEntityRender(manager);
		}
		
	}

	@Override
	public ResourceLocation getEntityTexture(AbstractHorseEntity entity) {
		return unicorn;
	}
}

 

package mod.dragonita.fantasymod.client.models;

import net.minecraft.client.renderer.entity.model.HorseModel;
import net.minecraft.entity.passive.horse.AbstractHorseEntity;

public class UnicornEntityModel extends HorseModel<AbstractHorseEntity>
{

	public UnicornEntityModel(float p_i51065_1_) {
		super(p_i51065_1_);
	}

}

 

Im have troubles here:

package mod.dragonita.fantasymod.client.renders;

import mod.dragonita.fantasymod.entities.UnicornEntity;
import mod.dragonita.fantasymod.init.FantasyModEntities;
import mod.dragonita.fantasymod.init.ModEntities;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.passive.horse.HorseEntity;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.fml.client.registry.RenderingRegistry;

@OnlyIn(Dist.CLIENT)
public class FantasyRenderRegistry
{
	@SuppressWarnings("unchecked")
	public static void registryEntityRenders()
	{
		RenderingRegistry.registerEntityRenderingHandler((EntityType<? extends HorseEntity>) FantasyModEntities.UNICORN_ENTITY, new UnicornEntityRender.RenderFactory()); //Here i have my errors message
	}
}

I am getting the following error message: 

The method registerEntityRenderingHandler(EntityType<T>, IRenderFactory<? super T>) in the type RenderingRegistry is not applicable for the arguments (EntityType<capture#2-of ? extends HorseEntity>, UnicornEntityRender.RenderFactory)

I already say thank you for all your help.

New in Modding? == Still learning!

Link to comment
Share on other sites

4 hours ago, diesieben07 said:

Do not create registry entries in a static initializer. Use the DeferredRegister class.

I am new in Java and Modding. What is a registry entrie?

4 hours ago, diesieben07 said:

Do not use @OnlyIn.

Why?

4 hours ago, diesieben07 said:

The error message says that the arguments you are trying to pass to registerEntityRenderingHandler are not valid. Check the method parameters and their types and make sure your arguments match.

I arleady made this, but i am new and i dont find what i made wrong. Its want a entity type and i have arleady write my entity type, but it have still continue to send me this error message. I tried, but it dont work.

New in Modding? == Still learning!

Link to comment
Share on other sites

6 hours ago, DragonITA said:

I am new in Java and Modding. What is a registry entrie?

Any implementation of IForgeRegistry (blocks, items, etc). These should be created during the appropiate registry event.

 

6 hours ago, DragonITA said:

I arleady made this, but i am new and i dont find what i made wrong. Its want a entity type and i have arleady write my entity type, but it have still continue to send me this error message. I tried, but it dont work.

This is basic Java syntax. If you are struggling with this then you need to learn Java before making a mod. This is not a Java forum.

Edited by DavidM
  • Like 1

Some tips:

Spoiler

Modder Support:

Spoiler

1. Do not follow tutorials on YouTube, especially TechnoVision (previously called Loremaster) and HarryTalks, due to their promotion of bad practice and usage of outdated code.

2. Always post your code.

3. Never copy and paste code. You won't learn anything from doing that.

4. 

Quote

Programming via Eclipse's hotfixes will get you nowhere

5. Learn to use your IDE, especially the debugger.

6.

Quote

The "picture that's worth 1000 words" only works if there's an obvious problem or a freehand red circle around it.

Support & Bug Reports:

Spoiler

1. Read the EAQ before asking for help. Remember to provide the appropriate log(s).

2. Versions below 1.11 are no longer supported due to their age. Update to a modern version of Minecraft to receive support.

 

 

Link to comment
Share on other sites

On 1/5/2020 at 1:50 AM, DavidM said:

This is basic Java syntax. If you are struggling with this then you need to learn Java before making a mod. This is not a Java forum.

Ok, thanks. What is a EntityType? Is this my Entity or something else? Auf jedenfalls arbeite ich gerade um dieses Problem lösen können.

 

On 1/4/2020 at 2:38 PM, diesieben07 said:

Use the DeferredRegister class.

Should i replace the RenderingRegistry with the DeferredRegister?

 

Ok, I know that I'm annoying you with my questions, and I also tried to look at some vanilla code, but all I need is this: In which folder is the Entity RenderRegistry? I'm looking for a solution to my problem right now, and as it is written in the tips from @DavidM: The best way to learn is to look at the vanilla code. So I've been thinking and want to look at a classic code. I'm just now noticing how many things I have to work on, so I want to finish this topic first and then improve myself, because it must be really annoying to try to help someone who doesn't know anything.

 

 

Thanks for reading it.

Edited by DragonITA
I switched Tom with DavidM, no idea why I wrote Tom.

New in Modding? == Still learning!

Link to comment
Share on other sites

7 minutes ago, diesieben07 said:

EntityType is just that: A type of entity, such as "creeper" or "zombie".

It simply is the Type of my Entity, my Entity in others word. Can i use my Entity like a EntityType?

Edit: I was so stupid, the solution was before my eyes for the whole time. I already made an EntityType, just had to import it.

Edited by DragonITA
I found a solution to my first problem.

New in Modding? == Still learning!

Link to comment
Share on other sites

@diesieben07, i'm sorry, I was just checking to make sure. 

Ok, so if I understood and read well then I should implement the IForgeRegistryEntry in a class. The (hopefully last) question: Where should I implement it, in which class? I don't want to take any risk, but if I have read it then I have to implement it in my entity class. Am I right?

New in Modding? == Still learning!

Link to comment
Share on other sites

On 1/4/2020 at 2:38 PM, diesieben07 said:

The error message says that the arguments you are trying to pass to registerEntityRenderingHandler are not valid. Check the method parameters and their types and make sure your arguments match.

I resolved it.

New in Modding? == Still learning!

Link to comment
Share on other sites

33 minutes ago, diesieben07 said:

You would know this if you had read the (already linked) documentation:

On 1/5/2020 at 1:54 PM, diesieben07 said:

I read it, only dont have see the difference between client physical side and client logical side.

this is what my IDE shows me (Tried to look at a vanilla code):

@net.minecraftforge.api.distmarker.OnlyIn(value=net.minecraftforge.api.distmarker.Dist.CLIENT)

I know it's exactly the same. But I don't understand that, even with the link you've already given. I just find it hard to understand that, and except for these four differences I don't understand at all. Why do you say I can't do it this way, but the vanilla code does exactly that? Could you explain it to me (And yes, I repeat, I read the link and still don't understand it)?

New in Modding? == Still learning!

Link to comment
Share on other sites

 

2 minutes ago, diesieben07 said:

However the code is not identical of course, some things (like GUIs or world rendering) only exist on the client. These things are marked by forge using @OnlyIn to signify "I only found this in distribution X".

(Similarly some things may only exist in the dedicated server distribution, but is going to be a much, much shorter list that is largely irrelevant for modding).

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

21 minutes ago, diesieben07 said:

A more modern name for physical side is "distribution".

 

This is the physical client (client distribution):
image.png.0820c9f02aa62ed957151d303e846c1c.png

When you start a single-player world it starts a logical client and a logical server (the integrated server). The distribution remains client, even for the integrated server. You don't suddenly have a dedicated server running.

When you connect to a server it starts a logical client.

 

This is the physical server (server distribution):

image.png.83f15c573a349cbf20abd8690109f69b.png

It only contains one logical side: The server. The distribution is always server.

 

Well, it definitely exists.

 

@OnlyIn is a forge thing. Vanilla does not have this.

During setup, forge merges the minecraft client jar and the server jar together (the two distributions, see the images above if you don't know the difference) to create one codebase.

However the code is not identical of course, some things (like GUIs or world rendering) only exist on the client. These things are marked by forge using @OnlyIn to signify "I only found this in distribution X".

Wow, thanks for that answer. Now I understand everything except for one point: Why can't I use @OnlyIn and what should I replace it with (the docs is really outdated soon and I don't know what to use now. Strange, when I pressed ctrl + spacebar in the IDE, then normal white comes up with a whole bunch of variables/functions I can use, but I haven't seen any FMLEnvironment.Dist)? If it is, then how should I use it? Usually my IDE tells me, but I don't see anything.

New in Modding? == Still learning!

Link to comment
Share on other sites

  • 3 weeks later...
On 1/8/2020 at 4:45 PM, DragonITA said:

I resolved it.

Can you please show your solution or tell me the name of the official java-class, that calls "registerEntityRenderingHandler" to register entity renderers?

I don´t know how to find this file, if i don´t know it´s name..

Edited by Drachenbauer
  • Like 1
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.



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • I have a block already registered in my mod, which I have used in some worlds. The problem arises when in code, I add a property called CURRENT_AGE, when running Minecraft it freezes. In the console it doesn't appear any excpetion except that it stays in this phase: [Render thread/DEBUG] [ne.mi.co.ca.CapabilityManager/CAPABILITIES]: Attempting to automatically register: Lnet/minecraftforge/items/IItemHandler; Does anyone have an idea what it could be? I show the block and its registration public class SoulLichenBlock extends MultifaceBlock implements SimpleWaterloggedBlock, EntityBlock { public static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED; public static final IntegerProperty SKILL_LEVEL = IntegerProperty.create("soullichen_level", 0, 30); public static final DirectionProperty FACE = DirectionProperty.create("soullichen_face"); public static final DirectionProperty DIRECTION = DirectionProperty.create("soullichen_direction"); public static final IntegerProperty CURRENT_AGE = BlockStateProperties.AGE_25; private final MultifaceSpreader spreader = new MultifaceSpreader(this); private final MultifaceSpreader.DefaultSpreaderConfig config = new MultifaceSpreader.DefaultSpreaderConfig(this); private LivingEntity owner; //private static final Integer MAX_AGE = 25; public SoulLichenBlock(Properties properties) { super(properties); this.registerDefaultState(this .defaultBlockState() .setValue(WATERLOGGED, Boolean.FALSE) .setValue(SKILL_LEVEL, 0) .setValue(FACE, Direction.DOWN) .setValue(DIRECTION, Direction.DOWN) .trySetValue(CURRENT_AGE, 0) ); } public static ToIntFunction<BlockState> emission(int p_181223_) { return (p_181221_) -> MultifaceBlock.hasAnyFace(p_181221_) ? p_181223_ : 0; } public static boolean hasFace(BlockState p_153901_, @NotNull Direction p_153902_) { BooleanProperty booleanproperty = getFaceProperty(p_153902_); return p_153901_.hasProperty(booleanproperty) && p_153901_.getValue(booleanproperty); } protected void createBlockStateDefinition(StateDefinition.@NotNull Builder<Block, BlockState> stateDefinition) { stateDefinition.add(WATERLOGGED).add(SKILL_LEVEL).add(FACE).add(DIRECTION).add(CURRENT_AGE); super.createBlockStateDefinition(stateDefinition); } public @NotNull BlockState updateShape(BlockState p_153302_, @NotNull Direction p_153303_, @NotNull BlockState p_153304_, @NotNull LevelAccessor p_153305_, @NotNull BlockPos p_153306_, @NotNull BlockPos p_153307_) { if (p_153302_.getValue(WATERLOGGED)) { p_153305_.scheduleTick(p_153306_, Fluids.WATER, Fluids.WATER.getTickDelay(p_153305_)); } return super.updateShape(p_153302_, p_153303_, p_153304_, p_153305_, p_153306_, p_153307_); } @SuppressWarnings("deprecation") public @NotNull FluidState getFluidState(BlockState fluidState) { return fluidState.getValue(WATERLOGGED) ? Fluids.WATER.getSource(false) : super.getFluidState(fluidState); } public boolean propagatesSkylightDown(BlockState p_181225_, @NotNull BlockGetter blockGetter, @NotNull BlockPos blockPos) { return p_181225_.getFluidState().isEmpty(); } public @NotNull MultifaceSpreader getSpreader() { return this.spreader; } public Optional<MultifaceSpreader.SpreadPos> spreadFromRandomFaceTowardRandomDirection( BlockState p_221620_, LevelAccessor p_221621_, BlockPos p_221622_, RandomSource p_221623_, int skillPoints, int age) { return Direction.allShuffled(p_221623_).stream().filter((p_221680_) -> { return this.config.canSpreadFrom(p_221620_, p_221680_); }).map((p_221629_) -> { return this.spreadFromFaceTowardRandomDirection(p_221620_, p_221621_, p_221622_, p_221629_, p_221623_, false, skillPoints, age); }).filter(Optional::isPresent).findFirst().orElse(Optional.empty()); } public Optional<MultifaceSpreader.SpreadPos> spreadFromFaceTowardRandomDirection( BlockState blockState, LevelAccessor levelAccessor, BlockPos blockPos, Direction face, RandomSource randomSource, boolean aBoolean, int skillPoints, int age) { return Direction.allShuffled(randomSource).stream().map((direction) -> spreadFromFaceTowardDirection(blockState, levelAccessor, blockPos, face, direction, aBoolean, skillPoints, age)) .filter(Optional::isPresent) .findFirst() .orElse(Optional.empty()); } public Optional<MultifaceSpreader.SpreadPos> spreadFromFaceTowardDirection( BlockState blockState, LevelAccessor levelAccessor, BlockPos blockPos, Direction face, Direction direction, boolean aBoolean, int skillPoints, int age) { //DevilRpg.LOGGER.debug("BEGIN ==================================== spreadFromFaceTowardDirection skillPoints {}", skillPoints); return skillPoints < 0 ? Optional.empty() : getSpreadFromFaceTowardDirection(blockState, levelAccessor, blockPos, face, direction, this::canSpreadInto) .flatMap((spreadPos) -> { //DevilRpg.LOGGER.debug("END ================================ spreadFromFaceTowardDirection spreadPos {}", spreadPos); return this.spreadToFace(levelAccessor, spreadPos, aBoolean, skillPoints, direction, age); }); } public boolean canSpreadInto(BlockGetter p_221685_, BlockPos p_221686_, MultifaceSpreader.SpreadPos p_221687_) { BlockState blockstate = p_221685_.getBlockState(p_221687_.pos()); return this.stateCanBeReplaced(p_221685_, p_221686_, p_221687_.pos(), p_221687_.face(), blockstate) && isValidStateForPlacement(p_221685_, blockstate, p_221687_.pos(), p_221687_.face()); } protected boolean stateCanBeReplaced(BlockGetter p_221688_, BlockPos p_221689_, BlockPos p_221690_, Direction p_221691_, BlockState p_221692_) { return p_221692_.isAir() || p_221692_.is(this) || p_221692_.is(Blocks.WATER) && p_221692_.getFluidState().isSource(); } public Optional<MultifaceSpreader.SpreadPos> getSpreadFromFaceTowardDirection(BlockState blockState, BlockGetter blockGetter, BlockPos blockPos, Direction face, Direction direction, MultifaceSpreader.SpreadPredicate spreadPredicate) { //DevilRpg.LOGGER.debug("--- getSpreadFromFaceTowardDirection direction.getAxis() == face.getAxis(): {}", direction.getAxis() == face.getAxis()); ArrayList<Direction> directions = new ArrayList<>(); directions.add(direction); if (direction.getAxis() == face.getAxis()) { if (direction.getAxis().isHorizontal()) { directions = Arrays.stream(Direction.values()).filter(dir -> dir.getAxis().isVertical()).collect(Collectors.toCollection(ArrayList::new)); } if (direction.getAxis().isVertical()) { directions = Arrays.stream(Direction.values()).filter(dir -> dir.getAxis().isHorizontal()).collect(Collectors.toCollection(ArrayList::new)); } } for (Direction directionElement : directions) { /*DevilRpg.LOGGER.debug("--->> getSpreadFromFaceTowardDirection config.isOtherBlockValidAsSource(blockState) {} || " + "hasFace(blockState, face) {} && " + "!hasFace(blockState, direction) {}", config.isOtherBlockValidAsSource(blockState), hasFace(blockState, face), !hasFace(blockState, directionElement));*/ if (config.isOtherBlockValidAsSource(blockState) || hasFace(blockState, face) && !hasFace(blockState, directionElement)) { for (MultifaceSpreader.SpreadType multifacespreader$spreadtype : config.getSpreadTypes()) { MultifaceSpreader.SpreadPos multifacespreader$spreadpos = multifacespreader$spreadtype.getSpreadPos(blockPos, directionElement, face); //DevilRpg.LOGGER.debug("--- test SpreadPos: {} direction {} face {} ", multifacespreader$spreadpos, directionElement, face); if (spreadPredicate.test(blockGetter, blockPos, multifacespreader$spreadpos)) { //DevilRpg.LOGGER.debug("--- spreadPredicate success:"); return Optional.of(multifacespreader$spreadpos); } } } } return Optional.empty(); } public boolean isValidStateForPlacement(@NotNull BlockGetter blockGetter, @NotNull BlockState blockState, @NotNull BlockPos blockPos, @NotNull Direction face) { //DevilRpg.LOGGER.debug("------ isValidStateForPlacement 1st condition: {} && ({} || {})", this.isFaceSupported(face), !blockState.is(this), !hasFace(blockState, face)); if (this.isFaceSupported(face) && (!blockState.is(this) || !hasFace(blockState, face))) { BlockPos blockpos = blockPos.relative(face); //DevilRpg.LOGGER.debug("------ isValidStateForPlacement 2nd condition: canAttachTo {} ", secondCondition); return canAttachTo(blockGetter, face, blockpos, blockGetter.getBlockState(blockpos)); } else { return false; } } @Nullable public BlockState getStateForPlacement(@NotNull BlockState blockState, @NotNull BlockGetter blockGetter, @NotNull BlockPos blockPos, @NotNull Direction face, int skillPoints, Direction direction, int age) { //DevilRpg.LOGGER.debug("--- getStateForPlacement"); boolean isNotValidStateForPlacement = !this.isValidStateForPlacement(blockGetter, blockState, blockPos, face); //DevilRpg.LOGGER.debug("------- isNotValidStateForPlacement: {}", isNotValidStateForPlacement); if (isNotValidStateForPlacement) { return null; } else { BlockState blockstate; if (blockState.is(this)) { blockstate = blockState; } else if (this.isWaterloggable() && blockState.getFluidState().isSourceOfType(Fluids.WATER)) { blockstate = this.defaultBlockState().setValue(BlockStateProperties.WATERLOGGED, Boolean.TRUE); } else { blockstate = this.defaultBlockState(); } //DevilRpg.LOGGER.debug("------- getStateForPlacement -> blockStateResult "); return blockstate .setValue(getFaceProperty(face), Boolean.TRUE) .setValue(SKILL_LEVEL, skillPoints).setValue(FACE, face) .setValue(DIRECTION, direction) .setValue(CURRENT_AGE,age) ; } } public Optional<MultifaceSpreader.SpreadPos> spreadToFace(LevelAccessor levelAccessor, MultifaceSpreader.SpreadPos spreadPos, boolean p_221596_, int skillPoints, Direction direction, int age) { BlockState blockstate = levelAccessor.getBlockState(spreadPos.pos()); //DevilRpg.LOGGER.debug("---> spreadToFace blockstate{} direction: {}", blockstate, direction); return this.placeBlock(levelAccessor, spreadPos, blockstate, p_221596_, skillPoints, direction, age) ? Optional.of(spreadPos) : Optional.empty(); } public boolean placeBlock(LevelAccessor p_221702_, MultifaceSpreader.SpreadPos p_221703_, BlockState p_221704_, boolean p_221705_, int skillPoints, Direction direction, int age) { //DevilRpg.LOGGER.debug("---> placeBlock {} direction {} ", p_221703_, direction); BlockState blockstate = this.getStateForPlacement(p_221704_, p_221702_, p_221703_.pos(), p_221703_.face(), skillPoints, direction, age); if (blockstate != null) { if (p_221705_) { p_221702_.getChunk(p_221703_.pos()).markPosForPostprocessing(p_221703_.pos()); } //DevilRpg.LOGGER.debug("------> setBlock"); return p_221702_.setBlock(p_221703_.pos(), blockstate, 2); } else { return false; } } public long spreadFromFaceTowardAllDirections( BlockState blockState, LevelAccessor levelAccessor, BlockPos blockPos, Direction face, boolean aBoolean, int skillPoints, int age) { return Direction.stream().map((p_221656_) -> spreadFromFaceTowardDirection(blockState, levelAccessor, blockPos, face, p_221656_, aBoolean, skillPoints, age)) .filter(Optional::isPresent).count(); } private boolean isWaterloggable() { return this.stateDefinition.getProperties().contains(BlockStateProperties.WATERLOGGED); } @Override public void setPlacedBy(@NotNull Level level, @NotNull BlockPos blockPos, @NotNull BlockState blockState, @Nullable LivingEntity livingEntity, @NotNull ItemStack itemStack) { super.setPlacedBy(level, blockPos, blockState, livingEntity, itemStack); this.setOwner(livingEntity); } public LivingEntity getOwner() { return this.owner; } private void setOwner(LivingEntity livingEntity) { this.owner = livingEntity; } @Deprecated @Override public void entityInside(@NotNull BlockState blockState, @NotNull Level level, @NotNull BlockPos blockPos, @NotNull Entity entity) { if (entity instanceof LivingEntity /*&& entity.getType() != EntityType.BEE*/ && entity.getType() != ModEntities.LICHEN_SEEDBALL.get()) { entity.makeStuckInBlock(blockState, new Vec3(0.8D, 0.75D, 0.8D)); if (!level.isClientSide /*&& (entity.xOld != entity.getX() || entity.zOld != entity.getZ())*/) { // double d0 = Math.abs(entity.getX() - entity.xOld); // double d1 = Math.abs(entity.getZ() - entity.zOld); // if (d0 >= (double) 0.003F || d1 >= (double) 0.003F) { entity.hurt(level.damageSources().playerAttack((Player) owner), 1.0F); // Aplicar aceleración al movimiento double speedBoost = -0.4; // Ajusta este valor según lo rápido que quieras que sea el impulso double motionX = entity.getX() - entity.xOld; double motionZ = entity.getZ() - entity.zOld; double speed = Math.sqrt(motionX * motionX + motionZ * motionZ); //if (speed > 0.0) { entity.setDeltaMovement(entity.getDeltaMovement().multiply( (motionX / speed) * speedBoost, 0.0, (motionZ / speed) * speedBoost )); // } //} } } } @Nullable @Override public BlockEntity newBlockEntity(@NotNull BlockPos pos, @NotNull BlockState state) { return ModEntityBlocks.SOUL_LICHEN_ENTITY_BLOCK.get().create(pos, state); } @Nullable @Override public <T extends BlockEntity> BlockEntityTicker<T> getTicker(Level level, @NotNull BlockState blockState, @NotNull BlockEntityType<T> type) { return level.isClientSide ? null : (alevel, pos, aBlockstate, blockEntity) -> { if (blockEntity instanceof SoulLichenBlockEntity soulLichenBlockEntity && alevel.getGameTime() % 5 == 0) { soulLichenBlockEntity.tick(blockState, (ServerLevel) alevel, pos, alevel.getRandom()); //DevilRpg.LOGGER.info("-------->tick. this: {}", this.getClass().getSimpleName()); } }; } }   This is the registration:   public final class ModBlocks { public static final DeferredRegister<Block> BLOCKS = DeferredRegister.create(ForgeRegistries.BLOCKS, DevilRpg.MODID); ... public static final RegistryObject<SoulLichenBlock> SOUL_LICHEN_BLOCK = BLOCKS.register("soullichen", () -> new SoulLichenBlock( Block.Properties.copy(Blocks.GLOW_LICHEN).lightLevel(SoulLichenBlock.emission(7)).randomTicks() )); }  
    • If you are using AMD/ATI, check for driver updates on their website - do not update via system
    • Hi, Create a new class that extends "Block" class and you need json for it in resources/assets/modid/blockstates directory and resources/assets/modid/models. You can generate json for it using a tool like misodes model generator. Here, atleast, are blocks explained at forge docs.  Don't forge to look at vanilla code, like Magma Block is a good reference if you're trying a "green fire block".  Modid should be replaced with your actual forge mod namespace!
    • Hi my game crash with exit code 1 forge 1.19.2 java 17.02 no mods installed, i tried with forge 1.20 and same error. Vanilla version function. This is the link for the log of launch of forge 1.20 https://pastebin.com/jxqTeZkN
    • I have no idea - it is still the same issue - but idk which mod Maybe panorama_screens
  • Topics

×
×
  • Create New...

Important Information

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