Jump to content

[1.8] Creating an Unique Tool with Durability [SOLVED]


kreezxil

Recommended Posts

Scenario:

I want to create a tool that is not based off of the sword, pickaxe, hoe, spade, or axe. The tool should have durability. The tool's intended use is to be used in a crafting grid as part of a recipe. The tool should not be destroyed by the recipe as long as it remains durable.

 

What I've done so far:

I haven't attempted any code in regard to the tool yet, but have view the tutorial at http://bedrockminer.jimdo.com/modding-tutorials/basic-modding-1-8/custom-tools-swords/ and can't help but think that is too complicated for what I want to do.

 

What I'm looking for:

Is that a good resource for this type of item? Is there are a better or more to the point tutorial or wiki for the type of tool I want to create?

Link to comment
Share on other sites

1) Extend

ItemTool

2) Have it override

hasContainerItem

and

getContainerItem

.  These will cause it to be left in the crafting grid and take damage (getContainerItem should return the same stack given, but with 1 point more damage).

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

1) Extend

ItemTool

2) Have it override

hasContainerItem

and

getContainerItem

.  These will cause it to be left in the crafting grid and take damage (getContainerItem should return the same stack given, but with 1 point more damage).

 

The item is still vanishing from the grid and I am sure that I arfed something up because if I try to hit any object with the item in hand the ssp world crashes.

 

Code for the class I created:

package com.kreezxil.modname.items;

import java.util.Set;

import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemTool;

public class durableCraftingTool extends ItemTool {

public durableCraftingTool(String unlocalizedName, float attackDamage, ToolMaterial material, Set effectiveBlocks) {
	super(attackDamage, material, effectiveBlocks);
	this.setUnlocalizedName(unlocalizedName);
}

public durableCraftingTool(String unlocalizedname, ToolMaterial material, Object effectiveBlocks) {
	this(unlocalizedname, 0.0f, material, (Set) effectiveBlocks);
}

@Override
public boolean hasContainerItem(ItemStack itemstack) {
	return false;
}

@Override
public ItemStack getContainerItem(ItemStack itemstack) {
	return new ItemStack(getContainerItem());
}
}

 

The error being thrown, not entirely sure what I need to be doing to fix:

[16:13:12] [Client thread/FATAL]: Unreported exception thrown!
java.lang.NullPointerException
at net.minecraft.item.ItemTool.getStrVsBlock(ItemTool.java:50) ~[itemTool.class:?]
at net.minecraft.item.Item.getDigSpeed(Item.java:575) ~[item.class:?]
at net.minecraft.item.ItemTool.getDigSpeed(ItemTool.java:162) ~[itemTool.class:?]
at net.minecraft.entity.player.EntityPlayer.getBreakSpeed(EntityPlayer.java:949) ~[EntityPlayer.class:?]
at net.minecraftforge.common.ForgeHooks.blockStrength(ForgeHooks.java:170) ~[ForgeHooks.class:?]
at net.minecraft.block.Block.getPlayerRelativeBlockHardness(Block.java:587) ~[block.class:?]
at net.minecraft.client.multiplayer.PlayerControllerMP.func_180511_b(PlayerControllerMP.java:250) ~[PlayerControllerMP.class:?]
at net.minecraft.client.Minecraft.clickMouse(Minecraft.java:1512) ~[Minecraft.class:?]
at net.minecraft.client.Minecraft.runTick(Minecraft.java:2118) ~[Minecraft.class:?]
at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1080) ~[Minecraft.class:?]
at net.minecraft.client.Minecraft.run(Minecraft.java:376) [Minecraft.class:?]
at net.minecraft.client.main.Main.main(Main.java:117) [Main.class:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_45]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_45]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_45]
at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_45]
at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) [launchwrapper-1.11.jar:?]
at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [launchwrapper-1.11.jar:?]
at net.minecraftforge.gradle.GradleStartCommon.launch(Unknown Source) [start/:?]
at GradleStart.main(Unknown Source) [start/:?]
[16:13:12] [Client thread/INFO] [sTDOUT]: [net.minecraft.init.Bootstrap:printToSYSOUT:660]: ---- Minecraft Crash Report ----
// Who set us up the TNT?

Time: 4/21/15 4:13 PM
Description: Unexpected error

java.lang.NullPointerException: Unexpected error
at net.minecraft.item.ItemTool.getStrVsBlock(ItemTool.java:50)
at net.minecraft.item.Item.getDigSpeed(Item.java:575)
at net.minecraft.item.ItemTool.getDigSpeed(ItemTool.java:162)
at net.minecraft.entity.player.EntityPlayer.getBreakSpeed(EntityPlayer.java:949)
at net.minecraftforge.common.ForgeHooks.blockStrength(ForgeHooks.java:170)
at net.minecraft.block.Block.getPlayerRelativeBlockHardness(Block.java:587)
at net.minecraft.client.multiplayer.PlayerControllerMP.func_180511_b(PlayerControllerMP.java:250)
at net.minecraft.client.Minecraft.clickMouse(Minecraft.java:1512)
at net.minecraft.client.Minecraft.runTick(Minecraft.java:2118)
at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1080)
at net.minecraft.client.Minecraft.run(Minecraft.java:376)
at net.minecraft.client.main.Main.main(Main.java:117)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at net.minecraft.launchwrapper.Launch.launch(Launch.java:135)
at net.minecraft.launchwrapper.Launch.main(Launch.java:28)
at net.minecraftforge.gradle.GradleStartCommon.launch(Unknown Source)
at GradleStart.main(Unknown Source)


A detailed walkthrough of the error, its code path and all known details is as follows:
---------------------------------------------------------------------------------------

-- Head --
Stacktrace:
at net.minecraft.item.ItemTool.getStrVsBlock(ItemTool.java:50)
at net.minecraft.item.Item.getDigSpeed(Item.java:575)
at net.minecraft.item.ItemTool.getDigSpeed(ItemTool.java:162)
at net.minecraft.entity.player.EntityPlayer.getBreakSpeed(EntityPlayer.java:949)
at net.minecraftforge.common.ForgeHooks.blockStrength(ForgeHooks.java:170)
at net.minecraft.block.Block.getPlayerRelativeBlockHardness(Block.java:587)
at net.minecraft.client.multiplayer.PlayerControllerMP.func_180511_b(PlayerControllerMP.java:250)
at net.minecraft.client.Minecraft.clickMouse(Minecraft.java:1512)

-- Affected level --
Details:
Level name: MpServer
All players: 1 total; [EntityPlayerSP['Player604'/83, l='MpServer', x=130.95, y=64.00, z=-221.63]]
Chunk stats: MultiplayerChunkCache: 624, 624
Level seed: 0
Level generator: ID 01 - flat, ver 0. Features enabled: false
Level generator options: 
Level spawn location: 130.00,4.00,-217.00 - World: (130,4,-217), Chunk: (at 2,0,7 in 8,-14; contains blocks 128,0,-224 to 143,255,-209), Region: (0,-1; contains chunks 0,-32 to 31,-1, blocks 0,0,-512 to 511,255,-1)
Level time: 13944 game time, 2610 day time
Level dimension: 0
Level storage version: 0x00000 - Unknown?
Level weather: Rain time: 0 (now: false), thunder time: 0 (now: false)
Level game mode: Game mode: survival (ID 0). Hardcore: false. Cheats: false
Forced entities: 28 total; [EntitySheep['Sheep'/64, l='MpServer', x=193.81, y=64.00, z=-183.94], EntitySheep['Sheep'/65, l='MpServer', x=185.88, y=64.00, z=-167.88], EntityPlayerSP['Player604'/83, l='MpServer', x=130.95, y=64.00, z=-221.63], EntityBat['Bat'/33540, l='MpServer', x=63.86, y=7.13, z=-292.38], EntityChicken['Chicken'/16, l='MpServer', x=56.56, y=64.00, z=-275.41], EntityChicken['Chicken'/17, l='MpServer', x=62.50, y=64.00, z=-268.50], EntityChicken['Chicken'/19, l='MpServer', x=59.50, y=64.00, z=-268.50], EntityChicken['Chicken'/20, l='MpServer', x=58.38, y=64.00, z=-268.69], EntityBat['Bat'/55640, l='MpServer', x=174.52, y=19.92, z=-241.20], EntityBat['Bat'/32, l='MpServer', x=66.42, y=7.46, z=-291.07], EntitySquid['Squid'/36, l='MpServer', x=90.31, y=62.38, z=-170.03], EntityBat['Bat'/40, l='MpServer', x=104.75, y=28.10, z=-193.53], EntityHorse['Horse'/42, l='MpServer', x=109.28, y=64.00, z=-180.38], EntityHorse['Horse'/45, l='MpServer', x=125.31, y=64.00, z=-181.72], EntityHorse['Horse'/46, l='MpServer', x=120.09, y=64.00, z=-161.75], EntitySquid['Squid'/55406, l='MpServer', x=148.50, y=61.00, z=-264.50], EntityRabbit['Rabbit'/47, l='MpServer', x=121.88, y=64.00, z=-162.91], EntityHorse['Horse'/48, l='MpServer', x=128.81, y=64.00, z=-179.72], EntitySquid['Squid'/59953, l='MpServer', x=171.50, y=61.47, z=-211.61], EntitySquid['Squid'/59954, l='MpServer', x=171.87, y=63.00, z=-210.66], EntitySquid['Squid'/59955, l='MpServer', x=128.39, y=61.38, z=-194.50], EntitySquid['Squid'/59956, l='MpServer', x=134.47, y=60.94, z=-193.41], EntityBat['Bat'/56, l='MpServer', x=175.47, y=21.10, z=-242.75], EntityBat['Bat'/57, l='MpServer', x=174.38, y=21.10, z=-242.75], EntityZombie['Zombie'/58, l='MpServer', x=172.53, y=20.00, z=-240.91], EntityBat['Bat'/59, l='MpServer', x=174.41, y=21.10, z=-242.75], EntitySheep['Sheep'/62, l='MpServer', x=205.50, y=64.00, z=-185.50], EntitySheep['Sheep'/63, l='MpServer', x=205.50, y=64.00, z=-182.50]]
Retry entities: 0 total; []
Server brand: fml,forge
Server type: Integrated singleplayer server
Stacktrace:
at net.minecraft.client.multiplayer.WorldClient.addWorldInfoToCrashReport(WorldClient.java:392)
at net.minecraft.client.Minecraft.addGraphicsAndWorldToCrashReport(Minecraft.java:2600)
at net.minecraft.client.Minecraft.run(Minecraft.java:405)
at net.minecraft.client.main.Main.main(Main.java:117)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at net.minecraft.launchwrapper.Launch.launch(Launch.java:135)
at net.minecraft.launchwrapper.Launch.main(Launch.java:28)
at net.minecraftforge.gradle.GradleStartCommon.launch(Unknown Source)
at GradleStart.main(Unknown Source)

-- System Details --
Details:
Minecraft Version: 1.8
Operating System: Windows 8.1 (amd64) version 6.3
Java Version: 1.8.0_45, Oracle Corporation
Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation
Memory: 744323400 bytes (709 MB) / 1056309248 bytes (1007 MB) up to 1056309248 bytes (1007 MB)
JVM Flags: 3 total; -Xincgc -Xmx1024M -Xms1024M
IntCache: cache: 0, tcache: 0, allocated: 0, tallocated: 0
FML: MCP v9.10 FML v8.0.76.1375 Minecraft Forge 11.14.1.1375 4 mods loaded, 4 mods active
mcp{9.05} [Minecraft Coder Pack] (minecraft.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
FML{8.0.76.1375} [Forge Mod Loader] (forgeSrc-1.8-11.14.1.1375.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
Forge{11.14.1.1375} [Minecraft Forge] (forgeSrc-1.8-11.14.1.1375.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
prismatics{0.1} [Prismatics] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
Loaded coremods (and transformers): 
Launched Version: 1.8
LWJGL: 2.9.1
OpenGL: GeForce GTX 460/PCIe/SSE2 GL version 4.5.0 NVIDIA 350.12, NVIDIA Corporation
GL Caps: Using GL 1.3 multitexturing.
Using GL 1.3 texture combiners.
Using framebuffer objects because OpenGL 3.0 is supported and separate blending is supported.
Shaders are available because OpenGL 2.1 is supported.
VBOs are available because OpenGL 1.5 is supported.

Using VBOs: No
Is Modded: Definitely; Client brand changed to 'fml,forge'
Type: Client (map_client.txt)
Resource Packs: []
Current Language: English (US)
Profiler Position: N/A (disabled)

Link to comment
Share on other sites

	@Override
public boolean hasContainerItem(ItemStack itemstack) {
	return false;
}

 

Dude.  False?  Really?

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

	@Override
public boolean hasContainerItem(ItemStack itemstack) {
	return false;
}

 

Dude.  False?  Really?

 

Heh? silly me. I thought the comment in the original code meant that it was returning true to begin with so "false" seemed obvious, now I realize it is a note telling me that I should return "true" if I want a specific behavior.

/**
     * ItemStack sensitive version of hasContainerItem
     * @param stack The current item stack
     * @return True if this item has a 'container'
     */
    public boolean hasContainerItem(ItemStack stack)
    {
        /**
         * True if this Item has a container item (a.k.a. crafting result)
         */
        return hasContainerItem(); //this part has a strikethrough in it in the item.class file.
    }

Link to comment
Share on other sites

I must be doing all kinds of things wrong here.

 

So I tried all the things mentioned here and managed to get the tool to lose durability and produce a new object as expected but at the same time crash the game.

 

Then I've tried to control it from the recipe side of things too, the result is that it no longer crashes, but now the durability doesn't go down. That code excerpt is:

		recipe = new ShapedOreRecipe(new ItemStack(ModBlocks.block_prism),"FQ",'F',ModItems.item_diamond_file.setContainerItem(ModItems.item_diamond_file),'Q',ModBlocks.block_quartz_glass);
	GameRegistry.addRecipe(recipe);

 

and the class where I think I tried everything is

package com.kreezxil.modname.items;

import java.util.Set;

import net.minecraft.block.Block;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemTool;
import net.minecraftforge.common.util.EnumHelper;

import com.google.common.collect.Sets;

public class durableCraftingTool extends ItemTool {

  //public static ToolMaterial DIAMONDFILE = EnumHelper.addToolMaterial("DIAMONDFILE", harvestLevel, maxUses, efficiency, damage, enchantability)//addToolMaterial("PRISMATICS", harvestLevel, durability, miningSpeed, damageVsEntities, enchantability);
public static ToolMaterial DIAMONDFILE = EnumHelper.addToolMaterial("DIAMONDFILE", 0, 3000, 2.0f, 0.5f, 22);
    private static final Set EFFECTIVE_ON = Sets.newHashSet(new Block[] {Blocks.air});

public durableCraftingTool(String unlocalizedName, float attackDamage, ToolMaterial material, Set effectiveBlocks) {
	super(attackDamage, material, effectiveBlocks);
	this.setUnlocalizedName(unlocalizedName);
}

public durableCraftingTool(String unlocalizedname, ToolMaterial material, Set effectiveBlocks) {
	this(unlocalizedname, 0.0f, material, (Set) effectiveBlocks);
}

public durableCraftingTool(String unlocalizedname) {
	this(unlocalizedname, DIAMONDFILE, EFFECTIVE_ON);
}

@Override
public boolean hasContainerItem(ItemStack itemstack) {
	return true;
}

@Override
public ItemStack getContainerItem(ItemStack itemstack) {
	return new ItemStack(getContainerItem());
}

}

 

Any and All help greatly appreciated.

Link to comment
Share on other sites

I must be doing all kinds of things wrong here.

 

So I tried all the things mentioned here and managed to get the tool to lose durability and produce a new object as expected but at the same time crash the game.

 

Ok, would you mind posting the crash report so we can see what error crashed the game?

 

P.S. I clicked the thank you button accidentally instead of quote. lol I don't think there is a way to reverse that. :/

  • Thanks 1
Link to comment
Share on other sites

I must be doing all kinds of things wrong here.

 

So I tried all the things mentioned here and managed to get the tool to lose durability and produce a new object as expected but at the same time crash the game.

 

Then I've tried to control it from the recipe side of things too, the result is that it no longer crashes, but now the durability doesn't go down. That code excerpt is:

		recipe = new ShapedOreRecipe(new ItemStack(ModBlocks.block_prism),"FQ",'F',ModItems.item_diamond_file.setContainerItem(ModItems.item_diamond_file),'Q',ModBlocks.block_quartz_glass);
	GameRegistry.addRecipe(recipe);

 

Wait, if it's a NullPointerException I think I had that on a recipe once. I was wondering what was wrong and I ended up fixing it by putting the recipe in an Object array. Like this:

GameRegistry.addShapedRecipe(new ItemStack(result), new Object[]{
"xxx",
"xxx",
"xxx",
'x', theCraftingitem
};

 

Although I don't know what ShapedOreRecipe is.

Link to comment
Share on other sites

Two things:

1. Did you override getContainerItem() to return an actual Item?

2. Why create a new ItemStack when you already have one?

@Override
public ItemStack getContainerItem(ItemStack itemstack) {
// Assuming you want to damage it when used in crafting:
itemstack.attemptDamageItem(1, this.itemRand);
return itemstack; // then just return it
}

Link to comment
Share on other sites

I must be doing all kinds of things wrong here.

 

So I tried all the things mentioned here and managed to get the tool to lose durability and produce a new object as expected but at the same time crash the game.

 

Ok, would you mind posting the crash report so we can see what error crashed the game?

 

P.S. I clicked the thank you button accidentally instead of quote. lol I don't think there is a way to reverse that. :/

 

I think that ShapedOreRecipe allows the components of the recipe to swap with other elements from other mods that would possibly match elements in the recipe. I could be wrong.

 

Here is crash report: http://pastebin.com/vmR83PLs

 

When I come back into the game, the tool will have lost one durability point but then at that point, I can no longer use it in a recipe. That recipe code follows:

GameRegistry.addRecipe(new ItemStack(ModBlocks.block_prism),"FQ",'F',ModItems.item_diamond_file,'Q',ModBlocks.block_quartz_glass);

 

 

Link to comment
Share on other sites

Two things:

1. Did you override getContainerItem() to return an actual Item?

2. Why create a new ItemStack when you already have one?

@Override
public ItemStack getContainerItem(ItemStack itemstack) {
// Assuming you want to damage it when used in crafting:
itemstack.attemptDamageItem(1, this.itemRand);
return itemstack; // then just return it
}

 

1. I did override as you found

2. all I can say is IRnewb. :(

3. I tried your suggestions and that got rid of the game crashing, but I can't use the subsequent new now damaged tool, how do I allow the damaged item to continue to be used in the recipe?

Link to comment
Share on other sites

Thanks to everyone in this thread, you all have gone a long way in helping to resolve the issue.

 

Resulting Code Follows ...

 

The recipe:

	GameRegistry.addRecipe(new ItemStack(ModBlocks.block_prism),"FQ",'F',new ItemStack(ModItems.item_diamond_file, 1, OreDictionary.WILDCARD_VALUE),'Q',ModBlocks.block_quartz_glass);

 

The class for the tool:

package com.kreezxil.prismatics.items;

import java.util.Set;

import net.minecraft.block.Block;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemTool;
import net.minecraftforge.common.util.EnumHelper;

import com.google.common.collect.Sets;

public class durableCraftingTool extends ItemTool {

  //public static ToolMaterial DIAMONDFILE = EnumHelper.addToolMaterial("DIAMONDFILE", harvestLevel, maxUses, efficiency, damage, enchantability)//addToolMaterial("PRISMATICS", harvestLevel, durability, miningSpeed, damageVsEntities, enchantability);
public static ToolMaterial DIAMONDFILE = EnumHelper.addToolMaterial("DIAMONDFILE", 0, 3000, 2.0f, 0.5f, 22);
    private static final Set EFFECTIVE_ON = Sets.newHashSet(new Block[] {Blocks.air});

public durableCraftingTool(String unlocalizedName, float attackDamage, ToolMaterial material, Set effectiveBlocks) {
	super(attackDamage, material, effectiveBlocks);
	this.setUnlocalizedName(unlocalizedName);
}

public durableCraftingTool(String unlocalizedname, ToolMaterial material, Set effectiveBlocks) {
	this(unlocalizedname, 0.0f, material, (Set) effectiveBlocks);
}

public durableCraftingTool(String unlocalizedname) {
	this(unlocalizedname, DIAMONDFILE, EFFECTIVE_ON);
}

@Override
public boolean hasContainerItem(ItemStack itemstack) {
	return true;
}

@Override
public ItemStack getContainerItem(ItemStack itemstack) {
	itemstack.attemptDamageItem(1, this.itemRand);
	return itemstack;
}

}

 

The code that creates the tool:

	GameRegistry.registerItem(item_diamond_file = new durableCraftingTool("item_diamond_file"),"item_diamond_file");

 

It is my sincerest hope that this thread will help others create tools that can be used in a crafting grid without losing the tool.

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.