Skip to content

Commit

Permalink
removed most of the block entity stuff from BlockInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
Trinsdar committed Oct 26, 2023
1 parent 0a1953f commit 5ab897a
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,22 +83,19 @@ public void addBlocks(Map<BlockPos, BlockInfo> renderedBlocks) {
public void addBlock(BlockPos pos, BlockInfo blockInfo) {
if (blockInfo.getBlockState().getBlock() == Blocks.AIR)
return;
if (blockInfo.getTileEntity() != null) {
blockInfo.getTileEntity().setLevel(this);
}
this.renderedBlocks.put(pos, blockInfo);
minPos.set(Math.min(minPos.x(), pos.getX()), Math.min(minPos.y(), pos.getY()), Math.min(minPos.z(), pos.getZ()));
maxPos.set(Math.max(maxPos.x(), pos.getX()), Math.max(maxPos.y(), pos.getY()), Math.max(maxPos.z(), pos.getZ()));
}

@Override
public void setBlockEntity(BlockEntity entity) {
renderedBlocks.put(entity.getBlockPos(), new BlockInfo(renderedBlocks.getOrDefault(entity.getBlockPos(), BlockInfo.EMPTY).getBlockState(), entity));
renderedBlocks.put(entity.getBlockPos(), new BlockInfo(renderedBlocks.getOrDefault(entity.getBlockPos(), BlockInfo.EMPTY).getBlockState()));

}
@Override
public boolean setBlock(@NotNull BlockPos pos, BlockState state, int a, int b) {
renderedBlocks.put(pos, new BlockInfo(state, renderedBlocks.getOrDefault(pos, BlockInfo.EMPTY).getTileEntity()));
renderedBlocks.put(pos, new BlockInfo(state));
return true;
}

Expand Down
19 changes: 3 additions & 16 deletions common/src/main/java/muramasa/antimatter/structure/BlockInfo.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package muramasa.antimatter.structure;

import com.google.common.base.Preconditions;
import lombok.Getter;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
Expand All @@ -13,39 +14,25 @@
* This includes block state and tile entity, and needed for complete representation
* of some complex blocks like machines, when rendering or manipulating them without world instance
*/
@Getter
public class BlockInfo {

public static final BlockInfo EMPTY = new BlockInfo(Blocks.AIR);

private final BlockState blockState;
private final BlockEntity tileEntity;

public BlockInfo(Block block) {
this(block.defaultBlockState());
}

public BlockInfo(BlockState blockState) {
this(blockState, null);
}
public BlockInfo(BlockState blockState, BlockEntity tileEntity) {
this.blockState = blockState;
this.tileEntity = tileEntity;
Preconditions.checkArgument(tileEntity == null || blockState.hasBlockEntity(),
"Cannot create block info with tile entity for block not having it");
}

public BlockState getBlockState() {
return blockState;
}

public BlockEntity getTileEntity() {
return tileEntity;
return null;
}

public void apply(Level world, BlockPos pos) {
world.setBlockAndUpdate(pos, blockState);
if (tileEntity != null) {
world.setBlockEntity(tileEntity);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,7 @@ public PatternBuilder at(String key, Machine<?> machine, Tier tier, Direction fr
} else {
state = block.defaultBlockState().setValue(BlockStateProperties.HORIZONTAL_FACING, frontSide);
}
//TODO 1.18
BlockEntity te = block.newBlockEntity(null, state);
return at(key, new BlockInfo(state, te));
return at(key, new BlockInfo(state));
}

public PatternBuilder shallowCopy() {
Expand Down

0 comments on commit 5ab897a

Please sign in to comment.