53 lines
1.9 KiB
Java
53 lines
1.9 KiB
Java
package com.thebrokenrail.energonrelics.block.entity.structure;
|
|
|
|
import com.thebrokenrail.energonrelics.block.structure.ResearchComplexGeneratorBlock;
|
|
import com.thebrokenrail.energonrelics.structure.StructurePart;
|
|
import com.thebrokenrail.energonrelics.structure.StructurePlacer;
|
|
import com.thebrokenrail.energonrelics.structure.researchcomplex.ResearchComplexStartPart;
|
|
import com.thebrokenrail.energonrelics.structure.researchcomplex.ResearchComplexState;
|
|
import net.minecraft.block.BlockState;
|
|
import net.minecraft.block.Blocks;
|
|
import net.minecraft.block.entity.BlockEntity;
|
|
import net.minecraft.block.entity.BlockEntityType;
|
|
import net.minecraft.nbt.CompoundTag;
|
|
import net.minecraft.util.Tickable;
|
|
import net.minecraft.util.math.Direction;
|
|
|
|
import java.util.Collections;
|
|
import java.util.Objects;
|
|
import java.util.Random;
|
|
|
|
public class ResearchComplexGeneratorBlockEntity extends BlockEntity implements Tickable {
|
|
private long seed = 0;
|
|
|
|
public ResearchComplexGeneratorBlockEntity(BlockEntityType<?> type) {
|
|
super(type);
|
|
}
|
|
|
|
public void setSeed(long seed) {
|
|
this.seed = seed;
|
|
}
|
|
|
|
@Override
|
|
public CompoundTag toTag(CompoundTag tag) {
|
|
super.toTag(tag);
|
|
tag.putLong("Seed", seed);
|
|
return tag;
|
|
}
|
|
|
|
@Override
|
|
public void fromTag(BlockState state, CompoundTag tag) {
|
|
super.fromTag(state, tag);
|
|
seed = tag.getLong("Seed");
|
|
}
|
|
|
|
@Override
|
|
public void tick() {
|
|
if (hasWorld() && !Objects.requireNonNull(getWorld()).isClient()) {
|
|
Direction facing = getCachedState().get(ResearchComplexGeneratorBlock.HORIZONTAL_FACING);
|
|
getWorld().setBlockState(getPos(), Blocks.STONE.getDefaultState());
|
|
new StructurePlacer(new ResearchComplexStartPart(new ResearchComplexState(getWorld(), new Random(seed)), Collections.singletonList(StructurePart.getTransformationFromDirection(facing)))).place(getWorld(), getPos());
|
|
}
|
|
}
|
|
}
|