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 javax.annotation.Nonnull;
import java.util.List;
@OnlyIn(Dist.CLIENT)
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) {
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) {
String[] array = new String[]{this.tileFeeder.currentAnimalAmount + " " + I18n.get("info." + ActuallyAdditions.MODID + ".gui.animals"), this.tileFeeder.currentAnimalAmount >= 2 && this.tileFeeder.currentAnimalAmount < TileEntityFeeder.THRESHOLD
? I18n.get("info." + ActuallyAdditions.MODID + ".gui.enoughToBreed")
List<Component> array = List.of(
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
? I18n.get("info." + ActuallyAdditions.MODID + ".gui.tooMany")
: I18n.get("info." + ActuallyAdditions.MODID + ".gui.notEnough")};
//this.drawHoveringText(Arrays.asList(array), x, y);
? Component.translatable("info." + ActuallyAdditions.MODID + ".gui.tooMany")
: Component.translatable("info." + ActuallyAdditions.MODID + ".gui.notEnough")
);
guiGraphics.renderComponentTooltip(this.font, array, x, y);
}
}

View file

@ -86,12 +86,12 @@ public class TileEntityFeeder extends TileEntityInventoryBase implements MenuPro
int range = 5;
ItemStack stack = tile.inv.getStackInSlot(0);
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();
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()) {
feedAnimal(opt.get());
tile.feedAnimal(opt.get());
stack.shrink(1);
tile.currentTimer = 0;
tile.setChanged();
@ -110,7 +110,7 @@ public class TileEntityFeeder extends TileEntityInventoryBase implements MenuPro
return (slot, automation) -> !automation;
}
private static void feedAnimal(Animal animal) {
private void feedAnimal(Animal animal) {
animal.setInLove(null);
for (int i = 0; i < 7; i++) {
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()) {
Item item = stack.getItem();
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.smooth_black_quartz_block": "Smooth Black Quartz",
"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_double": "Double Crusher",
"block.actuallyadditions.powered_furnace": "Powered Furnace",