Infusion starts by placing ingredients at any pedestals.

This commit is contained in:
Aleksey 2021-01-23 13:08:29 +03:00
parent f62f88e4bd
commit 482dcc1638
3 changed files with 34 additions and 67 deletions

View file

@ -38,39 +38,32 @@ public class EternalPedestal extends PedestalBlock {
} }
@Override @Override
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) { public void checkRitual(World world, BlockPos pos) {
ActionResult result = super.onUse(state, world, pos, player, hand, hit); BlockEntity blockEntity = world.getBlockEntity(pos);
if (result.equals(ActionResult.SUCCESS)) { if (blockEntity instanceof EternalPedestalEntity) {
BlockEntity blockEntity = world.getBlockEntity(pos); EternalPedestalEntity pedestal = (EternalPedestalEntity) blockEntity;
if (blockEntity instanceof EternalPedestalEntity) { BlockState updatedState = world.getBlockState(pos);
EternalPedestalEntity pedestal = (EternalPedestalEntity) blockEntity; if (pedestal.isEmpty() && updatedState.get(ACTIVATED)) {
BlockState updatedState = world.getBlockState(pos); if (pedestal.hasRitual()) {
if (pedestal.isEmpty() && updatedState.get(ACTIVATED)) { EternalRitual ritual = pedestal.getRitual();
ritual.removePortal();
}
world.setBlockState(pos, updatedState.with(ACTIVATED, false));
} else {
ItemStack itemStack = pedestal.getStack(0);
if (itemStack.getItem() == EndItems.ETERNAL_CRYSTAL) {
world.setBlockState(pos, updatedState.with(ACTIVATED, true));
if (pedestal.hasRitual()) { if (pedestal.hasRitual()) {
EternalRitual ritual = pedestal.getRitual(); pedestal.getRitual().checkStructure();
ritual.removePortal(); } else {
} EternalRitual ritual = new EternalRitual(world, pos);
world.setBlockState(pos, updatedState.with(ACTIVATED, false)); ritual.checkStructure();
} else {
ItemStack itemStack = pedestal.getStack(0);
if (itemStack.getItem() == EndItems.ETERNAL_CRYSTAL) {
world.setBlockState(pos, updatedState.with(ACTIVATED, true));
if (pedestal.hasRitual()) {
pedestal.getRitual().checkStructure();
} else {
EternalRitual ritual = new EternalRitual(world, pos);
ritual.checkStructure();
}
} }
} }
} }
} }
return result;
} }
@Override
protected void activate(World world, BlockPos pos, PlayerEntity player, BlockHitResult hit) {}
@Override @Override
public BlockState getStateForNeighborUpdate(BlockState state, Direction direction, BlockState newState, WorldAccess world, BlockPos pos, BlockPos posFrom) { public BlockState getStateForNeighborUpdate(BlockState state, Direction direction, BlockState newState, WorldAccess world, BlockPos pos, BlockPos posFrom) {
BlockState updated = super.getStateForNeighborUpdate(state, direction, newState, world, pos, posFrom); BlockState updated = super.getStateForNeighborUpdate(state, direction, newState, world, pos, posFrom);

View file

@ -28,42 +28,20 @@ public class InfusionPedestal extends PedestalBlock {
} }
@Override @Override
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) { public void checkRitual(World world, BlockPos pos) {
if (world.isClient || !state.isOf(this)) return ActionResult.CONSUME;
BlockEntity blockEntity = world.getBlockEntity(pos); BlockEntity blockEntity = world.getBlockEntity(pos);
InfusionPedestalEntity pedestal = null;
if (blockEntity instanceof InfusionPedestalEntity) { if (blockEntity instanceof InfusionPedestalEntity) {
pedestal = (InfusionPedestalEntity) blockEntity; InfusionPedestalEntity pedestal = (InfusionPedestalEntity) blockEntity;
if (!pedestal.isEmpty() && pedestal.hasRitual()) { if (pedestal.hasRitual()) {
if (pedestal.getRitual().hasRecipe()) { pedestal.getRitual().checkRecipe();
pedestal.getRitual().stop(); } else {
return ActionResult.SUCCESS; InfusionRitual ritual = new InfusionRitual(world, pos);
} else if (pedestal.getRitual().checkRecipe()) { pedestal.linkRitual(ritual);
return ActionResult.SUCCESS; ritual.checkRecipe();
}
} }
} }
ActionResult result = ActionResult.FAIL;
if (hand != null) {
result = super.onUse(state, world, pos, player, hand, hit);
}
if (result == ActionResult.SUCCESS) {
if (pedestal != null) {
if (pedestal.hasRitual()) {
pedestal.getRitual().checkRecipe();
} else {
InfusionRitual ritual = new InfusionRitual(world, pos);
pedestal.linkRitual(ritual);
ritual.checkRecipe();
}
}
}
return result;
} }
@Override
protected void activate(World world, BlockPos pos, PlayerEntity player, BlockHitResult hit) {}
@Override @Override
public BlockEntity createBlockEntity(BlockView world) { public BlockEntity createBlockEntity(BlockView world) {
return new InfusionPedestalEntity(); return new InfusionPedestalEntity();

View file

@ -114,7 +114,7 @@ public class PedestalBlock extends BlockBaseNotFull implements BlockEntityProvid
ItemStack itemStack = player.getStackInHand(hand); ItemStack itemStack = player.getStackInHand(hand);
if (itemStack.isEmpty()) return ActionResult.CONSUME; if (itemStack.isEmpty()) return ActionResult.CONSUME;
pedestal.setStack(0, itemStack.split(1)); pedestal.setStack(0, itemStack.split(1));
activate(world, pos, player, hit); this.checkRitual(world, pos);
return ActionResult.SUCCESS; return ActionResult.SUCCESS;
} else { } else {
ItemStack itemStack = pedestal.getStack(0); ItemStack itemStack = pedestal.getStack(0);
@ -128,17 +128,13 @@ public class PedestalBlock extends BlockBaseNotFull implements BlockEntityProvid
return ActionResult.PASS; return ActionResult.PASS;
} }
protected void activate(World world, BlockPos pos, PlayerEntity player, BlockHitResult hit) { public void checkRitual(World world, BlockPos pos) {
Mutable mut = new Mutable(); Mutable posMutable = new Mutable();
Point[] points = InfusionRitual.getMap(); for (Point point: InfusionRitual.getMap()) {
for (Point p: points) { posMutable.set(pos).move(point.x, 0, point.y);
mut.set(pos).move(p.x, 0, p.y); BlockState state = world.getBlockState(posMutable);
BlockState state = world.getBlockState(mut);
if (state.getBlock() instanceof InfusionPedestal) { if (state.getBlock() instanceof InfusionPedestal) {
ActionResult result = state.getBlock().onUse(state, world, mut, player, null, hit); ((InfusionPedestal) state.getBlock()).checkRitual(world, posMutable);
if (result == ActionResult.SUCCESS) {
break;
}
} }
} }
} }