WIP: infusion
This commit is contained in:
parent
a1d2e0d9bf
commit
beab6ce10a
6 changed files with 191 additions and 20 deletions
|
@ -16,6 +16,7 @@ import net.minecraft.world.BlockView;
|
|||
import net.minecraft.world.World;
|
||||
import ru.betterend.blocks.basis.BlockPedestal;
|
||||
import ru.betterend.blocks.entities.InfusionPedestalEntity;
|
||||
import ru.betterend.rituals.InfusionRitual;
|
||||
|
||||
public class InfusionPedestal extends BlockPedestal {
|
||||
private static final VoxelShape SHAPE_DEFAULT;
|
||||
|
@ -28,7 +29,28 @@ public class InfusionPedestal extends BlockPedestal {
|
|||
|
||||
@Override
|
||||
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
|
||||
BlockEntity blockEntity = world.getBlockEntity(pos);
|
||||
InfusionPedestalEntity pedestal = null;
|
||||
if (blockEntity instanceof InfusionPedestalEntity) {
|
||||
pedestal = (InfusionPedestalEntity) blockEntity;
|
||||
if (!pedestal.isEmpty() && pedestal.hasRitual()) {
|
||||
if (pedestal.getRitual().checkRecipe()) {
|
||||
return ActionResult.SUCCESS;
|
||||
}
|
||||
}
|
||||
}
|
||||
ActionResult 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;
|
||||
}
|
||||
|
||||
|
|
|
@ -2,23 +2,57 @@ package ru.betterend.blocks.entities;
|
|||
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import ru.betterend.rituals.InfusionRitual;
|
||||
|
||||
public class InfusionPedestalEntity extends PedestalBlockEntity {
|
||||
|
||||
private InfusionRitual activeRitual;
|
||||
private InfusionRitual linkedRitual;
|
||||
|
||||
@Override
|
||||
public void setLocation(World world, BlockPos pos) {
|
||||
super.setLocation(world, pos);
|
||||
if (hasRitual()) {
|
||||
this.linkedRitual.setLocation(world, pos);
|
||||
}
|
||||
}
|
||||
|
||||
public void linkRitual(InfusionRitual ritual) {
|
||||
this.linkedRitual = ritual;
|
||||
}
|
||||
|
||||
public InfusionRitual getRitual() {
|
||||
return this.linkedRitual;
|
||||
}
|
||||
|
||||
public boolean hasRitual() {
|
||||
return this.activeRitual != null;
|
||||
return this.linkedRitual != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
if (hasRitual()) {
|
||||
this.linkedRitual.tick();
|
||||
}
|
||||
super.tick();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromTag(BlockState state, CompoundTag tag) {
|
||||
if (tag.contains("ritual")) {
|
||||
this.linkedRitual = new InfusionRitual(world, pos);
|
||||
this.linkedRitual.fromTag(tag.getCompound("ritual"));
|
||||
}
|
||||
super.fromTag(state, tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompoundTag toTag(CompoundTag tag) {
|
||||
if (hasRitual()) {
|
||||
tag.put("ritual", linkedRitual.toTag(new CompoundTag()));
|
||||
}
|
||||
return super.toTag(tag);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue