Fix bales being rebuilt with only wheat and added option to trim bales with a hoe

This commit is contained in:
Sollace 2024-01-19 16:12:25 +00:00
parent e5236e5802
commit 08e1702a1a
No known key found for this signature in database
GPG key ID: E52FACE7B5C773DB
2 changed files with 29 additions and 17 deletions

View file

@ -19,8 +19,8 @@ import net.minecraft.block.HayBlock;
import net.minecraft.block.ShapeContext;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.registry.Registries;
import net.minecraft.registry.tag.ItemTags;
import net.minecraft.sound.SoundCategory;
import net.minecraft.state.StateManager;
import net.minecraft.state.property.BooleanProperty;
@ -107,13 +107,15 @@ public class EdibleBlock extends HayBlock {
}
private final Identifier baseBlock;
private final Identifier material;
public EdibleBlock(Identifier baseBlock, boolean register) {
public EdibleBlock(Identifier baseBlock, Identifier material, boolean register) {
super(Settings.copy(Blocks.HAY_BLOCK));
for (BooleanProperty segment : SEGMENTS) {
setDefaultState(getDefaultState().with(segment, true));
}
this.baseBlock = baseBlock;
this.material = material;
if (register) {
REGISTRY.add(this);
FlammableBlockRegistry.getDefaultInstance().add(this, 60, 20);
@ -148,7 +150,8 @@ public class EdibleBlock extends HayBlock {
}
ItemStack stack = player.getStackInHand(hand);
if (stack.isOf(Items.WHEAT)) {
if (!stack.isEmpty() && stack.isOf(Registries.ITEM.get(material))) {
BooleanProperty segment = getHitCorner(hit, 1);
if (!state.get(segment)) {
@ -160,7 +163,7 @@ public class EdibleBlock extends HayBlock {
}
world.setBlockState(pos, state);
}
world.playSound(player, pos, this.getSoundGroup(state).getPlaceSound(), SoundCategory.BLOCKS);
world.playSound(player, pos, getSoundGroup(state).getPlaceSound(), SoundCategory.BLOCKS);
return ActionResult.SUCCESS;
}
@ -174,9 +177,13 @@ public class EdibleBlock extends HayBlock {
return ActionResult.PASS;
}
boolean usingHoe = stack.isIn(ItemTags.HOES);
if (!usingHoe) {
if (!(player.isCreative() || player.getHungerManager().isNotFull()) || !player.isSneaking()) {
return ActionResult.FAIL;
}
}
if (!world.isClient) {
state = state.with(corner, false);
@ -186,11 +193,17 @@ public class EdibleBlock extends HayBlock {
world.setBlockState(pos, state);
}
}
if (usingHoe) {
dropStack(world, pos, Registries.ITEM.get(material).getDefaultStack());
player.playSound(USounds.Vanilla.ITEM_HOE_TILL, 1, 1);
} else {
player.playSound(USounds.Vanilla.ENTITY_GENERIC_EAT, 1, 1);
if (world.random.nextInt(10) == 0) {
player.playSound(USounds.Vanilla.ENTITY_PLAYER_BURP, 1, player.getSoundPitch());
}
player.getHungerManager().add(4, 2.3F);
}
return ActionResult.SUCCESS;
}
@ -202,13 +215,12 @@ public class EdibleBlock extends HayBlock {
return SEGMENTS[
(4 * getIndex(pos.y, bPos.getY()))
+ (2 * getIndex(pos.z, bPos.getZ()))
+ (1 - getIndex(pos.x, bPos.getX()))
+ (getIndex(pos.x, bPos.getX()))
];
}
static int getIndex(double axisHit, int tile) {
axisHit = Math.abs(axisHit);
tile = Math.abs(tile);
return axisHit - ((int)axisHit) > 0.5 ? 1 : 0;
axisHit -= tile;
return Math.abs(axisHit) > 0.5 ? 1 : 0;
}
}

View file

@ -225,7 +225,7 @@ public interface UBlocks {
Block CRYSTAL_DOOR = register("crystal_door", new CrystalDoorBlock(Settings.copy(Blocks.IRON_DOOR), UWoodTypes.CRYSTAL), ItemGroups.FUNCTIONAL);
Block CLOUD_DOOR = register("cloud_door", new CloudDoorBlock(Settings.copy(CLOUD), CLOUD.getDefaultState(), UWoodTypes.CLOUD), ItemGroups.FUNCTIONAL);
EdibleBlock HAY_BLOCK = register("hay_block", new EdibleBlock(new Identifier("hay_block"), true));
EdibleBlock HAY_BLOCK = register("hay_block", new EdibleBlock(new Identifier("hay_block"), new Identifier("wheat"), true));
private static <T extends Block> T register(String name, T item) {
return register(Unicopia.id(name), item);
@ -256,8 +256,8 @@ public interface UBlocks {
static void bootstrap() {
if (FabricLoader.getInstance().isModLoaded("farmersdelight")) {
register("rice_block", new EdibleBlock(new Identifier("farmersdelight", "rice_bale"), true));
register("straw_block", new EdibleBlock(new Identifier("farmersdelight", "straw_bale"), true));
register("rice_block", new EdibleBlock(new Identifier("farmersdelight", "rice_bale"), new Identifier("farmersdelight", "rice_panicle"), true));
register("straw_block", new EdibleBlock(new Identifier("farmersdelight", "straw_bale"), new Identifier("farmersdelight", "straw"), true));
}
BlockEntityTypeSupportHelper.of(BlockEntityType.SIGN).addSupportedBlocks(PALM_SIGN, PALM_WALL_SIGN);
BlockEntityTypeSupportHelper.of(BlockEntityType.HANGING_SIGN).addSupportedBlocks(PALM_HANGING_SIGN, PALM_WALL_HANGING_SIGN);