Automatic Feeder works

This commit is contained in:
Mrbysco 2024-03-12 16:35:48 +01:00
parent fb80bf33ef
commit 73be71afe5
3 changed files with 15 additions and 11 deletions

View file

@ -24,6 +24,7 @@ import net.neoforged.api.distmarker.Dist;
import net.neoforged.api.distmarker.OnlyIn; import net.neoforged.api.distmarker.OnlyIn;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import java.util.List;
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
public class GuiFeeder extends AAScreen<ContainerFeeder> { public class GuiFeeder extends AAScreen<ContainerFeeder> {
@ -42,12 +43,15 @@ public class GuiFeeder extends AAScreen<ContainerFeeder> {
public void render(@Nonnull GuiGraphics guiGraphics, int x, int y, float f) { public void render(@Nonnull GuiGraphics guiGraphics, int x, int y, float f) {
super.render(guiGraphics, x, y, f); super.render(guiGraphics, x, y, f);
if (x >= this.leftPos + 69 && y >= this.topPos + 30 && x <= this.leftPos + 69 + 10 && y <= this.topPos + 30 + 10) { if (x >= this.leftPos + 69 && y >= this.topPos + 30 && x <= this.leftPos + 69 + 10 && y <= this.topPos + 30 + 10) {
String[] array = new String[]{this.tileFeeder.currentAnimalAmount + " " + I18n.get("info." + ActuallyAdditions.MODID + ".gui.animals"), this.tileFeeder.currentAnimalAmount >= 2 && this.tileFeeder.currentAnimalAmount < TileEntityFeeder.THRESHOLD List<Component> array = List.of(
? I18n.get("info." + ActuallyAdditions.MODID + ".gui.enoughToBreed") Component.literal(this.tileFeeder.currentAnimalAmount + " ").append(Component.translatable("info." + ActuallyAdditions.MODID + ".gui.animals")),
this.tileFeeder.currentAnimalAmount >= 2 && this.tileFeeder.currentAnimalAmount < TileEntityFeeder.THRESHOLD
? Component.translatable("info." + ActuallyAdditions.MODID + ".gui.enoughToBreed")
: this.tileFeeder.currentAnimalAmount >= TileEntityFeeder.THRESHOLD : this.tileFeeder.currentAnimalAmount >= TileEntityFeeder.THRESHOLD
? I18n.get("info." + ActuallyAdditions.MODID + ".gui.tooMany") ? Component.translatable("info." + ActuallyAdditions.MODID + ".gui.tooMany")
: I18n.get("info." + ActuallyAdditions.MODID + ".gui.notEnough")}; : Component.translatable("info." + ActuallyAdditions.MODID + ".gui.notEnough")
//this.drawHoveringText(Arrays.asList(array), x, y); );
guiGraphics.renderComponentTooltip(this.font, array, x, y);
} }
} }

View file

@ -86,12 +86,12 @@ public class TileEntityFeeder extends TileEntityInventoryBase implements MenuPro
int range = 5; int range = 5;
ItemStack stack = tile.inv.getStackInSlot(0); ItemStack stack = tile.inv.getStackInSlot(0);
if (!stack.isEmpty() && tile.currentTimer >= TIME) { if (!stack.isEmpty() && tile.currentTimer >= TIME) {
List<Animal> animals = level.getEntitiesOfClass(Animal.class, new AABB(tile.worldPosition.getX() - range, tile.worldPosition.getY() - range, tile.worldPosition.getZ() - range, tile.worldPosition.getX() + range, tile.worldPosition.getY() + range, tile.worldPosition.getZ() + range)); List<Animal> animals = level.getEntitiesOfClass(Animal.class, new AABB(pos).inflate(range));
tile.currentAnimalAmount = animals.size(); tile.currentAnimalAmount = animals.size();
if (tile.currentAnimalAmount >= 2 && tile.currentAnimalAmount < THRESHOLD) { if (tile.currentAnimalAmount >= 2 && tile.currentAnimalAmount < THRESHOLD) {
Optional<Animal> opt = animals.stream().filter((e) -> canBeFed(stack, e)).findAny(); Optional<Animal> opt = animals.stream().filter((e) -> tile.canBeFed(stack, e)).findAny();
if (opt.isPresent()) { if (opt.isPresent()) {
feedAnimal(opt.get()); tile.feedAnimal(opt.get());
stack.shrink(1); stack.shrink(1);
tile.currentTimer = 0; tile.currentTimer = 0;
tile.setChanged(); tile.setChanged();
@ -110,7 +110,7 @@ public class TileEntityFeeder extends TileEntityInventoryBase implements MenuPro
return (slot, automation) -> !automation; return (slot, automation) -> !automation;
} }
private static void feedAnimal(Animal animal) { private void feedAnimal(Animal animal) {
animal.setInLove(null); animal.setInLove(null);
for (int i = 0; i < 7; i++) { for (int i = 0; i < 7; i++) {
double d = animal.level().random.nextGaussian() * 0.02D; double d = animal.level().random.nextGaussian() * 0.02D;
@ -120,7 +120,7 @@ public class TileEntityFeeder extends TileEntityInventoryBase implements MenuPro
} }
} }
private static boolean canBeFed(ItemStack stack, Animal animal) { private boolean canBeFed(ItemStack stack, Animal animal) {
if (animal instanceof Horse && ((Horse) animal).isTamed()) { if (animal instanceof Horse && ((Horse) animal).isTamed()) {
Item item = stack.getItem(); Item item = stack.getItem();
return animal.getAge() == 0 && !animal.isInLove() && (item == Items.GOLDEN_APPLE || item == Items.GOLDEN_CARROT); return animal.getAge() == 0 && !animal.isInLove() && (item == Items.GOLDEN_APPLE || item == Items.GOLDEN_CARROT);

View file

@ -105,7 +105,7 @@
"block.actuallyadditions.black_quartz_pillar_block": "Pillar of Black Quartz", "block.actuallyadditions.black_quartz_pillar_block": "Pillar of Black Quartz",
"block.actuallyadditions.smooth_black_quartz_block": "Smooth Black Quartz", "block.actuallyadditions.smooth_black_quartz_block": "Smooth Black Quartz",
"block.actuallyadditions.black_quartz_brick_block": "Black Quartz Bricks", "block.actuallyadditions.black_quartz_brick_block": "Black Quartz Bricks",
"block.actuallyadditions.feeder": "Automatic Feeder (wip)", "block.actuallyadditions.feeder": "Automatic Feeder",
"block.actuallyadditions.crusher": "Crusher", "block.actuallyadditions.crusher": "Crusher",
"block.actuallyadditions.crusher_double": "Double Crusher", "block.actuallyadditions.crusher_double": "Double Crusher",
"block.actuallyadditions.powered_furnace": "Powered Furnace", "block.actuallyadditions.powered_furnace": "Powered Furnace",