This commit is contained in:
Aleksey 2021-02-27 00:39:17 +03:00
parent db2a555ae9
commit 616c824257
6 changed files with 123 additions and 125 deletions

View file

@ -104,7 +104,7 @@ public class PedestalBlock extends BlockBaseNotFull implements BlockEntityProvid
@Override
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
if (world.isClient || !state.isOf(this)) return ActionResult.CONSUME;
if (!this.isPlaceable(state)) {
if (!isPlaceable(state)) {
return ActionResult.PASS;
}
BlockEntity blockEntity = world.getBlockEntity(pos);
@ -114,12 +114,12 @@ public class PedestalBlock extends BlockBaseNotFull implements BlockEntityProvid
ItemStack itemStack = player.getStackInHand(hand);
if (itemStack.isEmpty()) return ActionResult.CONSUME;
pedestal.setStack(0, itemStack.split(1));
this.checkRitual(world, pos);
checkRitual(world, pos);
return ActionResult.SUCCESS;
} else {
ItemStack itemStack = pedestal.getStack(0);
if (player.giveItemStack(itemStack)) {
pedestal.removeStack(world, state);
pedestal.removeStack(0);
return ActionResult.SUCCESS;
}
return ActionResult.FAIL;
@ -151,25 +151,25 @@ public class PedestalBlock extends BlockBaseNotFull implements BlockEntityProvid
boolean hasPedestalOver = upState.getBlock() instanceof PedestalBlock;
boolean hasPedestalUnder = downState.getBlock() instanceof PedestalBlock;
if (!hasPedestalOver && hasPedestalUnder && upSideSolid) {
return this.getDefaultState().with(STATE, PedestalState.COLUMN_TOP);
return getDefaultState().with(STATE, PedestalState.COLUMN_TOP);
} else if (!hasPedestalOver && !hasPedestalUnder && upSideSolid) {
return this.getDefaultState().with(STATE, PedestalState.COLUMN);
return getDefaultState().with(STATE, PedestalState.COLUMN);
} else if (hasPedestalUnder && hasPedestalOver) {
return this.getDefaultState().with(STATE, PedestalState.PILLAR);
return getDefaultState().with(STATE, PedestalState.PILLAR);
} else if (hasPedestalUnder) {
return this.getDefaultState().with(STATE, PedestalState.PEDESTAL_TOP);
return getDefaultState().with(STATE, PedestalState.PEDESTAL_TOP);
} else if (hasPedestalOver) {
return this.getDefaultState().with(STATE, PedestalState.BOTTOM);
return getDefaultState().with(STATE, PedestalState.BOTTOM);
}
return this.getDefaultState();
return getDefaultState();
}
@Override
public BlockState getStateForNeighborUpdate(BlockState state, Direction direction, BlockState newState, WorldAccess world, BlockPos pos, BlockPos posFrom) {
BlockState updated = this.getUpdatedState(state, direction, newState, world, pos, posFrom);
BlockState updated = getUpdatedState(state, direction, newState, world, pos, posFrom);
if (!updated.isOf(this)) return updated;
if (!this.isPlaceable(updated)) {
this.moveStoredStack(world, updated, pos);
if (!isPlaceable(updated)) {
moveStoredStack(world, updated, pos);
}
return updated;
}
@ -185,21 +185,27 @@ public class PedestalBlock extends BlockBaseNotFull implements BlockEntityProvid
if (direction == Direction.UP) {
upSideSolid = newState.isSideSolidFullSquare(world, posFrom, Direction.DOWN) || newState.isIn(BlockTags.WALLS);
hasPedestalOver = newState.getBlock() instanceof PedestalBlock;
} else if (direction == Direction.DOWN) {
} else {
hasPedestalUnder = newState.getBlock() instanceof PedestalBlock;
}
BlockState updatedState;
if (!hasPedestalOver && hasPedestalUnder && upSideSolid) {
return state.with(STATE, PedestalState.COLUMN_TOP);
updatedState = state.with(STATE, PedestalState.COLUMN_TOP);
} else if (!hasPedestalOver && !hasPedestalUnder && upSideSolid) {
return state.with(STATE, PedestalState.COLUMN);
updatedState = state.with(STATE, PedestalState.COLUMN);
} else if (hasPedestalUnder && hasPedestalOver) {
return state.with(STATE, PedestalState.PILLAR);
updatedState = state.with(STATE, PedestalState.PILLAR);
} else if (hasPedestalUnder) {
return state.with(STATE, PedestalState.PEDESTAL_TOP);
updatedState = state.with(STATE, PedestalState.PEDESTAL_TOP);
} else if (hasPedestalOver) {
return state.with(STATE, PedestalState.BOTTOM);
updatedState = state.with(STATE, PedestalState.BOTTOM);
} else {
updatedState = state.with(STATE, PedestalState.DEFAULT);
}
return state.with(STATE, PedestalState.DEFAULT);
if (!isPlaceable(updatedState)) {
updatedState = updatedState.with(HAS_ITEM, false).with(HAS_LIGHT, false);
}
return updatedState;
}
@Override
@ -208,7 +214,7 @@ public class PedestalBlock extends BlockBaseNotFull implements BlockEntityProvid
if (state.isOf(this)) {
if (isPlaceable(state)) {
BlockEntity blockEntity = builder.getNullable(LootContextParameters.BLOCK_ENTITY);
if (blockEntity != null && blockEntity instanceof PedestalBlockEntity) {
if (blockEntity instanceof PedestalBlockEntity) {
PedestalBlockEntity pedestal = (PedestalBlockEntity) blockEntity;
if (!pedestal.isEmpty()) {
drop.add(pedestal.getStack(0));
@ -222,63 +228,61 @@ public class PedestalBlock extends BlockBaseNotFull implements BlockEntityProvid
}
private void moveStoredStack(WorldAccess world, BlockState state, BlockPos pos) {
ItemStack stack = ItemStack.EMPTY;
BlockEntity blockEntity = world.getBlockEntity(pos);
if (blockEntity instanceof PedestalBlockEntity && state.isOf(this)) {
PedestalBlockEntity pedestal = (PedestalBlockEntity) blockEntity;
stack = pedestal.getStack(0);
pedestal.clear();
BlocksHelper.setWithoutUpdate(world, pos, state.with(HAS_ITEM, false));
}
if (!stack.isEmpty()) {
BlockPos upPos = pos.up();
this.moveStoredStack(world, stack, world.getBlockState(upPos), upPos);
ItemStack stack = pedestal.removeStack(0);
if (!stack.isEmpty()) {
moveStoredStack(blockEntity, world, stack, pos.up());
}
}
}
private void moveStoredStack(WorldAccess world, ItemStack stack, BlockState state, BlockPos pos) {
BlockEntity blockEntity = world.getBlockEntity(pos);
private void moveStoredStack(BlockEntity blockEntity, WorldAccess world, ItemStack stack, BlockPos pos) {
BlockState state = world.getBlockState(pos);
if (!state.isOf(this)) {
this.dropStoredStack(blockEntity, stack, pos);
dropStoredStack(blockEntity, stack, pos);
} else if (state.get(STATE).equals(PedestalState.PILLAR)) {
BlockPos upPos = pos.up();
this.moveStoredStack(world, stack, world.getBlockState(upPos), upPos);
} else if (!this.isPlaceable(state)) {
this.dropStoredStack(blockEntity, stack, pos);
moveStoredStack(blockEntity, world, stack, pos.up());
} else if (!isPlaceable(state)) {
dropStoredStack(blockEntity, stack, pos);
} else if (blockEntity instanceof PedestalBlockEntity) {
PedestalBlockEntity pedestal = (PedestalBlockEntity) blockEntity;
if (pedestal.isEmpty()) {
pedestal.setStack(0, stack);
} else {
this.dropStoredStack(blockEntity, stack, pos);
dropStoredStack(blockEntity, stack, pos);
}
} else {
this.dropStoredStack(blockEntity, stack, pos);
dropStoredStack(blockEntity, stack, pos);
}
}
private void dropStoredStack(BlockEntity blockEntity, ItemStack stack, BlockPos pos) {
if (blockEntity != null && blockEntity.getWorld() != null) {
World world = blockEntity.getWorld();
Block.dropStack(world, this.getDropPos(world, pos), stack);
Block.dropStack(world, getDropPos(world, pos), stack);
}
}
private BlockPos getDropPos(WorldAccess world, BlockPos pos) {
BlockPos dropPos;
if (world.getBlockState(pos).isAir()) {
return pos;
}
if (world.getBlockState(pos.up()).isAir()) {
return pos.up();
}
for(int i = 2; i < Direction.values().length; i++) {
dropPos = pos.offset(Direction.byId(i));
if (world.getBlockState(dropPos).isAir()) {
return dropPos.toImmutable();
}
}
if (world.getBlockState(pos.up()).isAir()) {
return pos.up();
}
return this.getDropPos(world, pos.up());
return getDropPos(world, pos.up());
}
protected boolean isPlaceable(BlockState state) {
public boolean isPlaceable(BlockState state) {
if (!state.isOf(this)) return false;
PedestalState currentState = state.get(STATE);
return currentState != PedestalState.BOTTOM &&

View file

@ -9,7 +9,6 @@ import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.packet.s2c.play.BlockEntityUpdateS2CPacket;
import net.minecraft.util.Tickable;
import net.minecraft.world.World;
import ru.betterend.blocks.basis.PedestalBlock;
import ru.betterend.registry.EndBlockEntities;
import ru.betterend.registry.EndItems;
@ -29,17 +28,11 @@ public class PedestalBlockEntity extends BlockEntity implements Inventory, Ticka
}
public int getAge() {
return this.age;
return age;
}
public int getMaxAge() {
return this.maxAge;
}
@Override
public void clear() {
this.activeItem = ItemStack.EMPTY;
this.markDirty();
return maxAge;
}
@Override
@ -49,42 +42,41 @@ public class PedestalBlockEntity extends BlockEntity implements Inventory, Ticka
@Override
public boolean isEmpty() {
return this.activeItem.isEmpty();
return activeItem.isEmpty();
}
@Override
public ItemStack getStack(int slot) {
return this.activeItem;
return activeItem;
}
@Override
public ItemStack removeStack(int slot, int amount) {
return this.removeStack(slot);
return removeStack(slot);
}
@Override
public boolean isValid(int slot, ItemStack stack) {
return this.isEmpty();
return isEmpty();
}
@Override
public void clear() {
activeItem = ItemStack.EMPTY;
markDirty();
}
@Override
public ItemStack removeStack(int slot) {
ItemStack stored = this.activeItem;
this.activeItem = ItemStack.EMPTY;
this.markDirty();
ItemStack stored = activeItem;
clear();
return stored;
}
public void removeStack(World world, BlockState state) {
world.setBlockState(pos, state.with(PedestalBlock.HAS_ITEM, false)
.with(PedestalBlock.HAS_LIGHT, false));
this.removeStack(0);
}
@Override
public void setStack(int slot, ItemStack stack) {
this.activeItem = stack;
this.markDirty();
activeItem = stack;
markDirty();
}
@Override
@ -92,17 +84,18 @@ public class PedestalBlockEntity extends BlockEntity implements Inventory, Ticka
if (world != null && !world.isClient) {
BlockState state = world.getBlockState(pos);
if (state.getBlock() instanceof PedestalBlock) {
state = state.with(PedestalBlock.HAS_ITEM, !isEmpty());
BlockState trueState = state.with(PedestalBlock.HAS_ITEM, !isEmpty());
if (activeItem.getItem() == EndItems.ETERNAL_CRYSTAL) {
state = state.with(PedestalBlock.HAS_LIGHT, true);
trueState = trueState.with(PedestalBlock.HAS_LIGHT, true);
} else {
state = state.with(PedestalBlock.HAS_LIGHT, false);
trueState = trueState.with(PedestalBlock.HAS_LIGHT, false);
}
world.setBlockState(pos, state);
world.setBlockState(pos, trueState);
}
}
super.markDirty();
}
@Override
public boolean canPlayerUse(PlayerEntity player) {
@ -111,12 +104,12 @@ public class PedestalBlockEntity extends BlockEntity implements Inventory, Ticka
@Override
public BlockEntityUpdateS2CPacket toUpdatePacket() {
return new BlockEntityUpdateS2CPacket(pos, 32, this.toInitialChunkDataTag());
return new BlockEntityUpdateS2CPacket(pos, 32, toInitialChunkDataTag());
}
@Override
public CompoundTag toInitialChunkDataTag() {
return this.toTag(new CompoundTag());
return toTag(new CompoundTag());
}
@Override
@ -124,7 +117,7 @@ public class PedestalBlockEntity extends BlockEntity implements Inventory, Ticka
super.fromTag(state, tag);
if (tag.contains("active_item")) {
CompoundTag itemTag = tag.getCompound("active_item");
this.activeItem = ItemStack.fromTag(itemTag);
activeItem = ItemStack.fromTag(itemTag);
}
}
@ -138,9 +131,9 @@ public class PedestalBlockEntity extends BlockEntity implements Inventory, Ticka
@Override
public void tick() {
if (!isEmpty()) {
this.age++;
age++;
if (age > maxAge) {
this.age = 0;
age = 0;
}
}
}

View file

@ -15,6 +15,7 @@ import net.minecraft.item.BlockItem;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.util.math.MathHelper;
import net.minecraft.world.World;
import ru.betterend.blocks.EternalPedestal;
import ru.betterend.blocks.basis.PedestalBlock;
import ru.betterend.blocks.entities.PedestalBlockEntity;
@ -34,16 +35,17 @@ public class PedestalItemRenderer<T extends PedestalBlockEntity> extends BlockEn
@Override
public void render(T blockEntity, float tickDelta, MatrixStack matrices,
VertexConsumerProvider vertexConsumers, int light, int overlay) {
if (blockEntity.isEmpty()) return;
BlockState state = blockEntity.getWorld().getBlockState(blockEntity.getPos());
World world = blockEntity.getWorld();
if (blockEntity.isEmpty() || world == null) return;
BlockState state = world.getBlockState(blockEntity.getPos());
if (!(state.getBlock() instanceof PedestalBlock)) return;
ItemStack activeItem = blockEntity.getStack(0);
matrices.push();
MinecraftClient minecraft = MinecraftClient.getInstance();
BakedModel model = minecraft.getItemRenderer().getHeldItemModel(activeItem, blockEntity.getWorld(), null);
BakedModel model = minecraft.getItemRenderer().getHeldItemModel(activeItem, world, null);
Vector3f translate = model.getTransformation().ground.translation;
PedestalBlock pedestal = (PedestalBlock) state.getBlock();
matrices.translate(translate.getX(), translate.getY(), translate.getZ());

View file

@ -10,8 +10,8 @@ import me.shedaniel.rei.api.RecipeDisplay;
import net.minecraft.util.Identifier;
public class REIAlloyingFuelDisplay implements RecipeDisplay {
private EntryStack fuel;
private int fuelTime;
private final EntryStack fuel;
private final int fuelTime;
public REIAlloyingFuelDisplay(EntryStack fuel, int fuelTime) {
this.fuel = fuel;

View file

@ -52,7 +52,6 @@ public class REIPlugin implements REIPluginV0 {
recipeHelper.registerRecipes(INFUSION, InfusionRecipe.class, REIInfusionDisplay::new);
FuelRegistryImpl.INSTANCE.getFuelTimes().forEach((item, time) -> {
if (time >= 2000) {
System.out.println(item);
recipeHelper.registerDisplay(new REIAlloyingFuelDisplay(EntryStack.create(item), time));
}
});

View file

@ -48,7 +48,7 @@ public class InfusionRitual implements Inventory {
if (world == null || world.isClient || worldPos == null) return;
BlockEntity inputEntity = world.getBlockEntity(worldPos);
if (inputEntity instanceof InfusionPedestalEntity) {
this.input = (InfusionPedestalEntity) inputEntity;
input = (InfusionPedestalEntity) inputEntity;
}
int i = 0;
for(Point point : PEDESTALS_MAP) {
@ -65,59 +65,59 @@ public class InfusionRitual implements Inventory {
public boolean checkRecipe() {
if (!isValid()) return false;
InfusionRecipe recipe = this.world.getRecipeManager().getFirstMatch(InfusionRecipe.TYPE, this, world).orElse(null);
InfusionRecipe recipe = world.getRecipeManager().getFirstMatch(InfusionRecipe.TYPE, this, world).orElse(null);
if (hasRecipe()) {
if (recipe == null) {
this.stop();
stop();
return false;
} else if (recipe.getInfusionTime() != time) {
this.activeRecipe = recipe;
this.time = this.activeRecipe.getInfusionTime();
this.progress = 0;
this.markDirty();
activeRecipe = recipe;
time = activeRecipe.getInfusionTime();
progress = 0;
markDirty();
} else if (activeRecipe == null) {
this.activeRecipe = recipe;
activeRecipe = recipe;
}
return true;
}
if (recipe != null) {
this.activeRecipe = recipe;
this.time = this.activeRecipe.getInfusionTime();
this.hasRecipe = true;
this.progress = 0;
this.markDirty();
activeRecipe = recipe;
time = activeRecipe.getInfusionTime();
hasRecipe = true;
progress = 0;
markDirty();
return true;
}
return false;
}
public void stop() {
this.activeRecipe = null;
this.hasRecipe = false;
this.progress = 0;
this.time = 0;
this.markDirty();
activeRecipe = null;
hasRecipe = false;
progress = 0;
time = 0;
markDirty();
}
public void tick() {
if (isDirty) {
this.configure();
this.isDirty = false;
configure();
isDirty = false;
}
if (!isValid() || !hasRecipe()) return;
if (!checkRecipe()) return;
this.progress++;
progress++;
if (progress == time) {
BlockState inputState = world.getBlockState(input.getPos());
this.input.removeStack(world, inputState);
this.input.setStack(0, activeRecipe.craft(this));
input.removeStack(0);
input.setStack(0, activeRecipe.craft(this));
for (PedestalBlockEntity catalyst : catalysts) {
catalyst.removeStack(world, world.getBlockState(catalyst.getPos()));
catalyst.removeStack(0);
}
this.stop();
stop();
} else {
ServerWorld world = (ServerWorld) this.world;
BlockPos target = this.worldPos.up();
BlockPos target = worldPos.up();
double tx = target.getX() + 0.5;
double ty = target.getY() + 0.5;
double tz = target.getZ() + 0.5;
@ -137,7 +137,7 @@ public class InfusionRitual implements Inventory {
@Override
public boolean isValid(int slot, ItemStack stack) {
return this.isValid();
return isValid();
}
public boolean isValid() {
@ -149,7 +149,7 @@ public class InfusionRitual implements Inventory {
}
public boolean hasRecipe() {
return this.hasRecipe;
return hasRecipe;
}
public void setLocation(World world, BlockPos pos) {
@ -161,7 +161,7 @@ public class InfusionRitual implements Inventory {
@Override
public void clear() {
if (!isValid()) return;
this.input.clear();
input.clear();
for (PedestalBlockEntity catalyst : catalysts) {
catalyst.clear();
}
@ -181,24 +181,24 @@ public class InfusionRitual implements Inventory {
public ItemStack getStack(int slot) {
if (slot > 8) return ItemStack.EMPTY;
if (slot == 0) {
return this.input.getStack(0);
return input.getStack(0);
} else {
return this.catalysts[slot - 1].getStack(0);
return catalysts[slot - 1].getStack(0);
}
}
@Override
public ItemStack removeStack(int slot, int amount) {
return this.removeStack(slot);
return removeStack(slot);
}
@Override
public ItemStack removeStack(int slot) {
if (slot > 8) return ItemStack.EMPTY;
if (slot == 0) {
return this.input.removeStack(0);
return input.removeStack(0);
} else {
return this.catalysts[slot - 1].getStack(0);
return catalysts[slot - 1].getStack(0);
}
}
@ -206,16 +206,16 @@ public class InfusionRitual implements Inventory {
public void setStack(int slot, ItemStack stack) {
if (slot > 8) return;
if (slot == 0) {
this.input.setStack(0, stack);
input.setStack(0, stack);
} else {
this.catalysts[slot - 1].setStack(0, stack);
catalysts[slot - 1].setStack(0, stack);
}
}
@Override
public void markDirty() {
if (isValid()) {
this.input.markDirty();
input.markDirty();
for (PedestalBlockEntity catalyst : catalysts) {
catalyst.markDirty();
}
@ -229,15 +229,15 @@ public class InfusionRitual implements Inventory {
public void fromTag(CompoundTag tag) {
if (tag.contains("recipe")) {
this.hasRecipe = tag.getBoolean("recipe");
this.progress = tag.getInt("progress");
this.time = tag.getInt("time");
hasRecipe = tag.getBoolean("recipe");
progress = tag.getInt("progress");
time = tag.getInt("time");
}
}
public CompoundTag toTag(CompoundTag tag) {
if (hasRecipe()) {
tag.putBoolean("recipe", this.hasRecipe);
tag.putBoolean("recipe", hasRecipe);
tag.putInt("progress", progress);
tag.putInt("time", time);
}