use of com.bluepowermod.tile.TileBPMultipart in project BluePower by Qmunity.
the class BlockBPMicroblock method setPlacedBy.
@Override
public void setPlacedBy(World worldIn, BlockPos pos, BlockState state, @Nullable LivingEntity placer, ItemStack stack) {
super.setPlacedBy(worldIn, pos, state, placer, stack);
TileEntity tileentity = worldIn.getBlockEntity(pos);
if (tileentity instanceof TileBPMicroblock && stack.hasTag() && stack.getTag().contains("block")) {
// Update Microblock Type based on Stack
Block block = ForgeRegistries.BLOCKS.getValue(new ResourceLocation(stack.getTag().getString("block")));
((TileBPMicroblock) tileentity).setBlock(block);
} else if (tileentity instanceof TileBPMultipart && stack.hasTag() && stack.getTag().contains("block")) {
// Update Multipart Microblock Type based on Stack
TileBPMicroblock tile = (TileBPMicroblock) ((TileBPMultipart) tileentity).getTileForState(state);
Block block = ForgeRegistries.BLOCKS.getValue(new ResourceLocation(stack.getTag().getString("block")));
tile.setBlock(block);
}
}
use of com.bluepowermod.tile.TileBPMultipart in project BluePower by Qmunity.
the class BlockBPMicroblock method getDrops.
@Override
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
TileEntity tileentity = builder.getParameter(LootParameters.BLOCK_ENTITY);
List<ItemStack> itemStacks = new ArrayList<>();
if (tileentity instanceof TileBPMultipart) {
tileentity = ((TileBPMultipart) tileentity).getTileForState(state);
}
if (tileentity instanceof TileBPMicroblock) {
CompoundNBT nbt = new CompoundNBT();
nbt.putString("block", ((TileBPMicroblock) tileentity).getBlock().getRegistryName().toString());
ItemStack stack = new ItemStack(this);
stack.setTag(nbt);
stack.setHoverName(new TranslationTextComponent(((TileBPMicroblock) tileentity).getBlock().getDescriptionId()).append(new StringTextComponent(" ")).append(new TranslationTextComponent(this.getDescriptionId())));
itemStacks.add(stack);
}
return itemStacks;
}
use of com.bluepowermod.tile.TileBPMultipart in project BluePower by Qmunity.
the class BlockInsulatedAlloyWire method getDrops.
@Override
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
TileEntity tileentity = builder.getParameter(LootParameters.BLOCK_ENTITY);
List<ItemStack> itemStacks = new ArrayList<>();
if (tileentity instanceof TileBPMultipart) {
tileentity = ((TileBPMultipart) tileentity).getTileForState(state);
}
if (tileentity instanceof TileInsulatedWire) {
CompoundNBT nbt = new CompoundNBT();
nbt.putString("color", ((TileInsulatedWire) tileentity).getColor().name());
ItemStack stack = new ItemStack(this, 1, nbt);
itemStacks.add(stack);
}
return itemStacks;
}
use of com.bluepowermod.tile.TileBPMultipart in project BluePower by Qmunity.
the class MultipartUtils method getClosestState.
/**
* Returns the closest Multipart state to the Vec3 in in a given position.
* @param world
* @param start
* @param end
* @param pos
*/
@Nullable
public static BlockState getClosestState(World world, Vector3d start, Vector3d end, BlockPos pos) {
TileEntity te = world.getBlockEntity(pos);
BlockState state = null;
double distance = Double.POSITIVE_INFINITY;
if (te instanceof TileBPMultipart) {
for (BlockState part : ((TileBPMultipart) te).getStates()) {
RayTraceResult res = part.getVisualShape(world, pos, ISelectionContext.empty()).clip(start, end, pos);
if (res != null) {
double partDistance = start.distanceToSqr(res.getLocation());
if (distance > partDistance) {
distance = partDistance;
state = part;
}
}
}
}
return state;
}
use of com.bluepowermod.tile.TileBPMultipart in project BluePower by Qmunity.
the class BlockBPCableBase method getStateForPos.
private BlockState getStateForPos(World world, BlockPos pos, BlockState state, Direction face) {
List<Direction> directions = new ArrayList<>(FACING.getPossibleValues());
List<Direction> internal = null;
boolean connected_left = false;
boolean connected_right = false;
boolean connected_front = false;
boolean connected_back = false;
boolean join_left = false;
boolean join_right = false;
boolean join_front = false;
boolean join_back = false;
// Make sure the side we are trying to connect on isn't blocked.
TileEntity ownTile = world.getBlockEntity(pos);
if (ownTile instanceof TileBPMultipart) {
directions.removeIf(d -> ((TileBPMultipart) ownTile).isSideBlocked(getCapability(), d));
internal = ((TileBPMultipart) ownTile).getStates().stream().filter(s -> s.getBlock() == this).map(s -> s.getValue(FACING)).collect(Collectors.toList());
}
// Make sure the cable is on the same side of the block
directions.removeIf(d -> {
TileEntity t = world.getBlockEntity(pos.relative(d));
return (world.getBlockState(pos.relative(d)).getBlock() == this && world.getBlockState(pos.relative(d)).getValue(FACING) != face) || (t instanceof TileBPMultipart && ((TileBPMultipart) t).getStates().stream().noneMatch(s -> s.getValue(FACING) == face));
});
// Populate all directions
for (Direction d : directions) {
TileEntity tileEntity = world.getBlockEntity(pos.relative(d));
BlockState dirState = world.getBlockState(pos.relative(d));
BlockPos dirPos = pos.relative(d);
boolean join = false;
// If Air look for a change in Direction
if (world.getBlockState(pos.relative(d)).getBlock() == Blocks.AIR) {
dirState = world.getBlockState(pos.relative(d).relative(face.getOpposite()));
dirPos = pos.relative(d).relative(face.getOpposite());
if (dirState.getBlock() == this && dirState.getValue(FACING) == d) {
tileEntity = world.getBlockEntity(pos.relative(d).relative(face.getOpposite()));
join = true;
} else if (dirState.getBlock() instanceof BlockBPMultipart) {
tileEntity = world.getBlockEntity(pos.relative(d).relative(face.getOpposite()));
if (tileEntity instanceof TileBPMultipart && ((TileBPMultipart) tileEntity).getStates().stream().filter(s -> s.getBlock() == this).anyMatch(s -> s.getValue(FACING) == d)) {
join = true;
} else {
tileEntity = null;
}
}
}
// Check Capability for Direction
switch(state.getValue(FACING)) {
case UP:
case DOWN:
switch(d) {
case EAST:
connected_right = canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
join_right = join && canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
break;
case WEST:
connected_left = canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
join_left = join && canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
break;
case NORTH:
connected_front = canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
join_front = join && canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
break;
case SOUTH:
connected_back = canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
join_back = join && canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
break;
}
break;
case NORTH:
switch(d) {
case WEST:
connected_right = canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
join_right = join && canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
break;
case EAST:
connected_left = canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
join_left = join && canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
break;
case UP:
connected_front = canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
join_front = join && canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
break;
case DOWN:
connected_back = canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
join_back = join && canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
break;
}
break;
case SOUTH:
switch(d) {
case EAST:
connected_right = canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
join_right = join && canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
break;
case WEST:
connected_left = canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
join_left = join && canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
break;
case UP:
connected_front = canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
join_front = join && canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
break;
case DOWN:
connected_back = canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
join_back = join && canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
break;
}
break;
case EAST:
switch(d) {
case NORTH:
connected_right = canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
join_right = join && canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
break;
case SOUTH:
connected_left = canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
join_left = join && canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
break;
case UP:
connected_front = canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
join_front = join && canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
break;
case DOWN:
connected_back = canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
join_back = join && canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
break;
}
break;
case WEST:
switch(d) {
case SOUTH:
connected_right = canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
join_right = join && canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
break;
case NORTH:
connected_left = canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
join_left = join && canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
break;
case UP:
connected_front = canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
join_front = join && canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
break;
case DOWN:
connected_back = canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
join_back = join && canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
break;
}
}
}
if (internal != null)
for (Direction d : internal) {
switch(state.getValue(FACING)) {
case UP:
case DOWN:
switch(d) {
case EAST:
connected_left = true;
break;
case WEST:
connected_right = true;
break;
case NORTH:
connected_back = true;
break;
case SOUTH:
connected_front = true;
break;
}
break;
case NORTH:
switch(d) {
case WEST:
connected_left = true;
break;
case EAST:
connected_right = true;
break;
case UP:
connected_back = true;
break;
case DOWN:
connected_front = true;
break;
}
break;
case SOUTH:
switch(d) {
case EAST:
connected_left = true;
break;
case WEST:
connected_right = true;
break;
case UP:
connected_back = true;
break;
case DOWN:
connected_front = true;
break;
}
break;
case EAST:
switch(d) {
case NORTH:
connected_left = true;
break;
case SOUTH:
connected_right = true;
break;
case UP:
connected_back = true;
break;
case DOWN:
connected_front = true;
break;
}
break;
case WEST:
switch(d) {
case SOUTH:
connected_left = true;
break;
case NORTH:
connected_right = true;
break;
case UP:
connected_back = true;
break;
case DOWN:
connected_front = true;
break;
}
}
}
FluidState fluidstate = world.getFluidState(pos);
return state.setValue(CONNECTED_LEFT, connected_left).setValue(CONNECTED_RIGHT, connected_right).setValue(CONNECTED_FRONT, connected_front).setValue(CONNECTED_BACK, connected_back).setValue(JOIN_LEFT, join_left).setValue(JOIN_RIGHT, join_right).setValue(JOIN_FRONT, join_front).setValue(JOIN_BACK, join_back).setValue(WATERLOGGED, fluidstate.getType() == Fluids.WATER);
}
Aggregations