Continue mapping migration

This commit is contained in:
Aleksey 2021-04-12 21:38:22 +03:00
parent 99ade39404
commit f03fd03bd0
499 changed files with 12567 additions and 12723 deletions

View file

@ -1,24 +1,25 @@
package ru.betterend.rituals;
import java.awt.Point;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.inventory.Inventory;
import net.minecraft.world.item.ItemStack;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.Container;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.entity.BlockEntity;
import ru.betterend.blocks.entities.InfusionPedestalEntity;
import ru.betterend.blocks.entities.PedestalBlockEntity;
import ru.betterend.particle.InfusionParticleType;
import ru.betterend.recipe.builders.InfusionRecipe;
public class InfusionRitual implements Inventory {
private static final Point[] PEDESTALS_MAP = new Point[] { new Point(0, 3), new Point(2, 2), new Point(3, 0),
new Point(2, -2), new Point(0, -3), new Point(-2, -2), new Point(-3, 0), new Point(-2, 2) };
public class InfusionRitual implements Container {
private static final Point[] PEDESTALS_MAP = new Point[] {
new Point(0, 3), new Point(2, 2), new Point(3, 0), new Point(2, -2),
new Point(0, -3), new Point(-2, -2), new Point(-3, 0), new Point(-2, 2)
};
private Level world;
private BlockPos worldPos;
@ -27,31 +28,29 @@ public class InfusionRitual implements Inventory {
private boolean hasRecipe = false;
private int progress = 0;
private int time = 0;
private InfusionPedestalEntity input;
private final PedestalBlockEntity[] catalysts = new PedestalBlockEntity[8];
public InfusionRitual(Level world, BlockPos pos) {
this.world = world;
this.worldPos = pos;
this.configure();
}
public static Point[] getMap() {
return PEDESTALS_MAP;
}
public void configure() {
if (world == null || world.isClientSide || worldPos == null)
return;
if (world == null || world.isClientSide || worldPos == null) return;
BlockEntity inputEntity = world.getBlockEntity(worldPos);
if (inputEntity instanceof InfusionPedestalEntity) {
input = (InfusionPedestalEntity) inputEntity;
}
int i = 0;
for (Point point : PEDESTALS_MAP) {
BlockPos.MutableBlockPos checkPos = worldPos.mutable().move(Direction.EAST, point.x).move(Direction.NORTH,
point.y);
for(Point point : PEDESTALS_MAP) {
BlockPos.MutableBlockPos checkPos = worldPos.mutable().move(Direction.EAST, point.x).move(Direction.NORTH, point.y);
BlockEntity catalystEntity = world.getBlockEntity(checkPos);
if (catalystEntity instanceof PedestalBlockEntity) {
catalysts[i] = (PedestalBlockEntity) catalystEntity;
@ -61,11 +60,10 @@ public class InfusionRitual implements Inventory {
}
}
}
public boolean checkRecipe() {
if (!isValid())
return false;
InfusionRecipe recipe = world.getRecipeManager().getFirstMatch(InfusionRecipe.TYPE, this, world).orElse(null);
if (!isValid()) return false;
InfusionRecipe recipe = world.getRecipeManager().getRecipeFor(InfusionRecipe.TYPE, this, world).orElse(null);
if (hasRecipe()) {
if (recipe == null) {
stop();
@ -74,7 +72,7 @@ public class InfusionRitual implements Inventory {
activeRecipe = recipe;
time = activeRecipe.getInfusionTime();
progress = 0;
markDirty();
setChanged();
} else if (activeRecipe == null) {
activeRecipe = recipe;
}
@ -85,47 +83,45 @@ public class InfusionRitual implements Inventory {
time = activeRecipe.getInfusionTime();
hasRecipe = true;
progress = 0;
markDirty();
setChanged();
return true;
}
return false;
}
public void stop() {
activeRecipe = null;
hasRecipe = false;
progress = 0;
time = 0;
markDirty();
setChanged();
}
public void tick() {
if (isDirty) {
configure();
isDirty = false;
}
if (!isValid() || !hasRecipe())
return;
if (!checkRecipe())
return;
if (!isValid() || !hasRecipe()) return;
if (!checkRecipe()) return;
progress++;
if (progress == time) {
input.removeStack(0);
input.setStack(0, activeRecipe.craft(this));
input.removeItemNoUpdate(0);
input.setItem(0, activeRecipe.assemble(this));
for (PedestalBlockEntity catalyst : catalysts) {
catalyst.removeStack(0);
catalyst.removeItemNoUpdate(0);
}
stop();
} else {
ServerLevel world = (ServerLevel) this.world;
BlockPos target = worldPos.up();
BlockPos target = worldPos.above();
double tx = target.getX() + 0.5;
double ty = target.getY() + 0.5;
double tz = target.getZ() + 0.5;
for (PedestalBlockEntity catalyst : catalysts) {
ItemStack stack = catalyst.getStack(0);
ItemStack stack = catalyst.getItem(0);
if (!stack.isEmpty()) {
BlockPos start = catalyst.getPos();
BlockPos start = catalyst.getBlockPos();
double sx = start.getX() + 0.5;
double sy = start.getY() + 1.25;
double sz = start.getZ() + 0.5;
@ -133,24 +129,22 @@ public class InfusionRitual implements Inventory {
}
}
}
}
@Override
public boolean isValid(int slot, ItemStack stack) {
public boolean canPlaceItem(int slot, ItemStack stack) {
return isValid();
}
public boolean isValid() {
if (world == null || world.isClientSide || worldPos == null || input == null)
return false;
if (world == null || world.isClientSide || worldPos == null || input == null) return false;
for (PedestalBlockEntity catalyst : catalysts) {
if (catalyst == null)
return false;
if (catalyst == null) return false;
}
return true;
}
public boolean hasRecipe() {
return hasRecipe;
}
@ -162,17 +156,16 @@ public class InfusionRitual implements Inventory {
}
@Override
public void clear() {
if (!isValid())
return;
input.clear();
public void clearContent() {
if (!isValid()) return;
input.clearContent();
for (PedestalBlockEntity catalyst : catalysts) {
catalyst.clear();
catalyst.clearContent();
}
}
@Override
public int size() {
public int getContainerSize() {
return 9;
}
@ -182,58 +175,55 @@ public class InfusionRitual implements Inventory {
}
@Override
public ItemStack getStack(int slot) {
if (slot > 8)
return ItemStack.EMPTY;
public ItemStack getItem(int slot) {
if (slot > 8) return ItemStack.EMPTY;
if (slot == 0) {
return input.getStack(0);
return input.getItem(0);
} else {
return catalysts[slot - 1].getStack(0);
return catalysts[slot - 1].getItem(0);
}
}
@Override
public ItemStack removeStack(int slot, int amount) {
return removeStack(slot);
public ItemStack removeItem(int slot, int amount) {
return removeItemNoUpdate(slot);
}
@Override
public ItemStack removeStack(int slot) {
if (slot > 8)
return ItemStack.EMPTY;
public ItemStack removeItemNoUpdate(int slot) {
if (slot > 8) return ItemStack.EMPTY;
if (slot == 0) {
return input.removeStack(0);
return input.removeItemNoUpdate(0);
} else {
return catalysts[slot - 1].removeStack(0);
return catalysts[slot - 1].removeItemNoUpdate(0);
}
}
@Override
public void setStack(int slot, ItemStack stack) {
if (slot > 8)
return;
public void setItem(int slot, ItemStack stack) {
if (slot > 8) return;
if (slot == 0) {
input.setStack(0, stack);
input.setItem(0, stack);
} else {
catalysts[slot - 1].setStack(0, stack);
catalysts[slot - 1].setItem(0, stack);
}
}
@Override
public void markDirty() {
public void setChanged() {
if (isValid()) {
input.markDirty();
input.setChanged();
for (PedestalBlockEntity catalyst : catalysts) {
catalyst.markDirty();
catalyst.setChanged();
}
}
}
@Override
public boolean canPlayerUse(Player player) {
public boolean stillValid(Player player) {
return true;
}
public void fromTag(CompoundTag tag) {
if (tag.contains("recipe")) {
hasRecipe = tag.getBoolean("recipe");