mirror of
https://github.com/Sollace/Unicopia.git
synced 2024-11-30 16:28:00 +01:00
Fix bales being rebuilt with only wheat and added option to trim bales with a hoe
This commit is contained in:
parent
e5236e5802
commit
08e1702a1a
2 changed files with 29 additions and 17 deletions
|
@ -19,8 +19,8 @@ import net.minecraft.block.HayBlock;
|
||||||
import net.minecraft.block.ShapeContext;
|
import net.minecraft.block.ShapeContext;
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.item.Items;
|
|
||||||
import net.minecraft.registry.Registries;
|
import net.minecraft.registry.Registries;
|
||||||
|
import net.minecraft.registry.tag.ItemTags;
|
||||||
import net.minecraft.sound.SoundCategory;
|
import net.minecraft.sound.SoundCategory;
|
||||||
import net.minecraft.state.StateManager;
|
import net.minecraft.state.StateManager;
|
||||||
import net.minecraft.state.property.BooleanProperty;
|
import net.minecraft.state.property.BooleanProperty;
|
||||||
|
@ -107,13 +107,15 @@ public class EdibleBlock extends HayBlock {
|
||||||
}
|
}
|
||||||
|
|
||||||
private final Identifier baseBlock;
|
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));
|
super(Settings.copy(Blocks.HAY_BLOCK));
|
||||||
for (BooleanProperty segment : SEGMENTS) {
|
for (BooleanProperty segment : SEGMENTS) {
|
||||||
setDefaultState(getDefaultState().with(segment, true));
|
setDefaultState(getDefaultState().with(segment, true));
|
||||||
}
|
}
|
||||||
this.baseBlock = baseBlock;
|
this.baseBlock = baseBlock;
|
||||||
|
this.material = material;
|
||||||
if (register) {
|
if (register) {
|
||||||
REGISTRY.add(this);
|
REGISTRY.add(this);
|
||||||
FlammableBlockRegistry.getDefaultInstance().add(this, 60, 20);
|
FlammableBlockRegistry.getDefaultInstance().add(this, 60, 20);
|
||||||
|
@ -148,7 +150,8 @@ public class EdibleBlock extends HayBlock {
|
||||||
}
|
}
|
||||||
|
|
||||||
ItemStack stack = player.getStackInHand(hand);
|
ItemStack stack = player.getStackInHand(hand);
|
||||||
if (stack.isOf(Items.WHEAT)) {
|
|
||||||
|
if (!stack.isEmpty() && stack.isOf(Registries.ITEM.get(material))) {
|
||||||
BooleanProperty segment = getHitCorner(hit, 1);
|
BooleanProperty segment = getHitCorner(hit, 1);
|
||||||
|
|
||||||
if (!state.get(segment)) {
|
if (!state.get(segment)) {
|
||||||
|
@ -160,7 +163,7 @@ public class EdibleBlock extends HayBlock {
|
||||||
}
|
}
|
||||||
world.setBlockState(pos, state);
|
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;
|
return ActionResult.SUCCESS;
|
||||||
}
|
}
|
||||||
|
@ -174,9 +177,13 @@ public class EdibleBlock extends HayBlock {
|
||||||
return ActionResult.PASS;
|
return ActionResult.PASS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
boolean usingHoe = stack.isIn(ItemTags.HOES);
|
||||||
|
|
||||||
|
if (!usingHoe) {
|
||||||
if (!(player.isCreative() || player.getHungerManager().isNotFull()) || !player.isSneaking()) {
|
if (!(player.isCreative() || player.getHungerManager().isNotFull()) || !player.isSneaking()) {
|
||||||
return ActionResult.FAIL;
|
return ActionResult.FAIL;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!world.isClient) {
|
if (!world.isClient) {
|
||||||
state = state.with(corner, false);
|
state = state.with(corner, false);
|
||||||
|
@ -186,11 +193,17 @@ public class EdibleBlock extends HayBlock {
|
||||||
world.setBlockState(pos, state);
|
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);
|
player.playSound(USounds.Vanilla.ENTITY_GENERIC_EAT, 1, 1);
|
||||||
if (world.random.nextInt(10) == 0) {
|
if (world.random.nextInt(10) == 0) {
|
||||||
player.playSound(USounds.Vanilla.ENTITY_PLAYER_BURP, 1, player.getSoundPitch());
|
player.playSound(USounds.Vanilla.ENTITY_PLAYER_BURP, 1, player.getSoundPitch());
|
||||||
}
|
}
|
||||||
player.getHungerManager().add(4, 2.3F);
|
player.getHungerManager().add(4, 2.3F);
|
||||||
|
}
|
||||||
return ActionResult.SUCCESS;
|
return ActionResult.SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -202,13 +215,12 @@ public class EdibleBlock extends HayBlock {
|
||||||
return SEGMENTS[
|
return SEGMENTS[
|
||||||
(4 * getIndex(pos.y, bPos.getY()))
|
(4 * getIndex(pos.y, bPos.getY()))
|
||||||
+ (2 * getIndex(pos.z, bPos.getZ()))
|
+ (2 * getIndex(pos.z, bPos.getZ()))
|
||||||
+ (1 - getIndex(pos.x, bPos.getX()))
|
+ (getIndex(pos.x, bPos.getX()))
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
static int getIndex(double axisHit, int tile) {
|
static int getIndex(double axisHit, int tile) {
|
||||||
axisHit = Math.abs(axisHit);
|
axisHit -= tile;
|
||||||
tile = Math.abs(tile);
|
return Math.abs(axisHit) > 0.5 ? 1 : 0;
|
||||||
return axisHit - ((int)axisHit) > 0.5 ? 1 : 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 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);
|
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) {
|
private static <T extends Block> T register(String name, T item) {
|
||||||
return register(Unicopia.id(name), item);
|
return register(Unicopia.id(name), item);
|
||||||
|
@ -256,8 +256,8 @@ public interface UBlocks {
|
||||||
|
|
||||||
static void bootstrap() {
|
static void bootstrap() {
|
||||||
if (FabricLoader.getInstance().isModLoaded("farmersdelight")) {
|
if (FabricLoader.getInstance().isModLoaded("farmersdelight")) {
|
||||||
register("rice_block", new EdibleBlock(new Identifier("farmersdelight", "rice_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"), 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.SIGN).addSupportedBlocks(PALM_SIGN, PALM_WALL_SIGN);
|
||||||
BlockEntityTypeSupportHelper.of(BlockEntityType.HANGING_SIGN).addSupportedBlocks(PALM_HANGING_SIGN, PALM_WALL_HANGING_SIGN);
|
BlockEntityTypeSupportHelper.of(BlockEntityType.HANGING_SIGN).addSupportedBlocks(PALM_HANGING_SIGN, PALM_WALL_HANGING_SIGN);
|
||||||
|
|
Loading…
Reference in a new issue