[Fix] Custom Item Drop for a Sign is created before the Blocks are registered (quiqueck/BetterNether#151)
This commit is contained in:
parent
13cd641ee0
commit
1448ea8467
5 changed files with 46 additions and 12 deletions
|
@ -147,7 +147,7 @@ public class BCLib implements ModInitializer {
|
|||
);
|
||||
bockReg.registerBlockOnly(
|
||||
makeID("test_wall_sign"),
|
||||
TEST_SIGN.wallSign
|
||||
TEST_SIGN.getWallSignBlock()
|
||||
);
|
||||
bockReg.register(
|
||||
makeID("test_hanging_sign"),
|
||||
|
@ -155,7 +155,7 @@ public class BCLib implements ModInitializer {
|
|||
);
|
||||
bockReg.registerBlockOnly(
|
||||
makeID("test_wall_hanging_sign"),
|
||||
TEST_HANGING_SIGN.wallSign
|
||||
TEST_HANGING_SIGN.getWallSignBlock()
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -25,9 +25,12 @@ import net.minecraft.world.level.block.state.properties.WoodType;
|
|||
import net.minecraft.world.level.material.MapColor;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public abstract class BaseHangingSignBlock extends CeilingHangingSignBlock implements BlockModelProvider, CustomItemProvider, TagProvider {
|
||||
public final BaseWallHangingSignBlock wallSign;
|
||||
protected final Supplier<BaseWallHangingSignBlock> wallSign;
|
||||
private BlockItem customItem;
|
||||
private BaseWallHangingSignBlock wallSignBlock;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface WallSignProvider {
|
||||
|
@ -36,9 +39,15 @@ public abstract class BaseHangingSignBlock extends CeilingHangingSignBlock imple
|
|||
|
||||
protected BaseHangingSignBlock(WoodType type, MapColor color, boolean flammable, WallSignProvider provider) {
|
||||
super(BehaviourBuilders.createSign(color, flammable), type);
|
||||
this.wallSign = provider.create(BehaviourBuilders.createWallSign(color, this, flammable), type);
|
||||
this.wallSign = () -> provider.create(BehaviourBuilders.createWallSign(color, this, flammable), type);
|
||||
}
|
||||
|
||||
public BaseWallHangingSignBlock getWallSignBlock() {
|
||||
if (wallSignBlock == null) {
|
||||
wallSignBlock = wallSign.get();
|
||||
}
|
||||
return wallSignBlock;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getYRotationDegrees(BlockState blockState) {
|
||||
|
@ -47,7 +56,10 @@ public abstract class BaseHangingSignBlock extends CeilingHangingSignBlock imple
|
|||
|
||||
@Override
|
||||
public BlockItem getCustomItem(ResourceLocation blockID, Item.Properties settings) {
|
||||
return new HangingSignItem(this, wallSign, settings.stacksTo(16));
|
||||
if (customItem == null) {
|
||||
customItem = new HangingSignItem(this, getWallSignBlock(), settings.stacksTo(16));
|
||||
}
|
||||
return customItem;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package org.betterx.bclib.blocks.signs;
|
||||
|
||||
import org.betterx.bclib.api.v3.datagen.DropSelfLootProvider;
|
||||
import org.betterx.bclib.behaviours.BehaviourBuilders;
|
||||
import org.betterx.bclib.behaviours.interfaces.BehaviourExplosionResistant;
|
||||
import org.betterx.bclib.behaviours.interfaces.BehaviourWood;
|
||||
import org.betterx.bclib.complexmaterials.BCLWoodTypeWrapper;
|
||||
import org.betterx.bclib.interfaces.BlockModelProvider;
|
||||
|
@ -13,6 +15,7 @@ import net.minecraft.tags.ItemTags;
|
|||
import net.minecraft.tags.TagKey;
|
||||
import net.minecraft.world.item.BlockItem;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.SignItem;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.StandingSignBlock;
|
||||
|
@ -20,12 +23,17 @@ import net.minecraft.world.level.block.state.BlockState;
|
|||
import net.minecraft.world.level.block.state.properties.RotationSegment;
|
||||
import net.minecraft.world.level.block.state.properties.WoodType;
|
||||
import net.minecraft.world.level.material.MapColor;
|
||||
import net.minecraft.world.level.storage.loot.LootParams;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public abstract class BaseSignBlock extends StandingSignBlock implements BlockModelProvider, CustomItemProvider, TagProvider {
|
||||
public final BaseWallSignBlock wallSign;
|
||||
public abstract class BaseSignBlock extends StandingSignBlock implements BlockModelProvider, CustomItemProvider, TagProvider, DropSelfLootProvider<BaseSignBlock>, BehaviourExplosionResistant {
|
||||
protected final Supplier<BaseWallSignBlock> wallSign;
|
||||
private BlockItem customItem;
|
||||
private BaseWallSignBlock wallSignBlock;
|
||||
|
||||
|
||||
@FunctionalInterface
|
||||
public interface WallSignProvider {
|
||||
|
@ -34,9 +42,15 @@ public abstract class BaseSignBlock extends StandingSignBlock implements BlockMo
|
|||
|
||||
protected BaseSignBlock(WoodType type, MapColor color, boolean flammable, WallSignProvider provider) {
|
||||
super(BehaviourBuilders.createSign(color, flammable), type);
|
||||
this.wallSign = provider.create(BehaviourBuilders.createWallSign(color, this, flammable), type);
|
||||
this.wallSign = () -> provider.create(BehaviourBuilders.createWallSign(color, this, flammable), type);
|
||||
}
|
||||
|
||||
public BaseWallSignBlock getWallSignBlock() {
|
||||
if (wallSignBlock == null) {
|
||||
wallSignBlock = wallSign.get();
|
||||
}
|
||||
return wallSignBlock;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public float getYRotationDegrees(BlockState blockState) {
|
||||
|
@ -45,7 +59,10 @@ public abstract class BaseSignBlock extends StandingSignBlock implements BlockMo
|
|||
|
||||
@Override
|
||||
public BlockItem getCustomItem(ResourceLocation blockID, Item.Properties settings) {
|
||||
return new SignItem(settings.stacksTo(16), this, wallSign);
|
||||
if (customItem == null) {
|
||||
customItem = new SignItem(settings, this, getWallSignBlock());
|
||||
}
|
||||
return customItem;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -71,4 +88,9 @@ public abstract class BaseSignBlock extends StandingSignBlock implements BlockMo
|
|||
public static BaseSignBlock from(BCLWoodTypeWrapper type) {
|
||||
return new BaseSignBlock.Wood(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ItemStack> getDrops(BlockState blockState, LootParams.Builder builder) {
|
||||
return super.getDrops(blockState, builder);
|
||||
}
|
||||
}
|
|
@ -33,7 +33,7 @@ public class HangingSign extends MaterialSlot<WoodenComplexMaterial> {
|
|||
false,
|
||||
(complexMaterial, settings) -> {
|
||||
if (complexMaterial.getBlock(suffix) instanceof BaseHangingSignBlock sign) {
|
||||
return sign.wallSign;
|
||||
return sign.getWallSignBlock();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ public class Sign extends MaterialSlot<WoodenComplexMaterial> {
|
|||
false,
|
||||
(complexMaterial, settings) -> {
|
||||
if (complexMaterial.getBlock(suffix) instanceof BaseSignBlock sign) {
|
||||
return sign.wallSign;
|
||||
return sign.getWallSignBlock();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue