use of gregtech.common.blocks.BlockFrame in project GregTech by GregTechCE.
the class FoamSprayerBehavior method gatherFrameBlocks.
private static List<BlockPos> gatherFrameBlocks(World worldIn, BlockPos centerPos, int maxRadiusSq) {
HashSet<BlockPos> observedSet = new HashSet<>();
ArrayList<BlockPos> resultFrameBlocks = new ArrayList<>();
observedSet.add(centerPos);
resultFrameBlocks.add(centerPos);
IBlockState frameState = null;
Stack<EnumFacing> moveStack = new Stack<>();
MutableBlockPos currentPos = new MutableBlockPos(centerPos);
main: while (true) {
for (EnumFacing facing : EnumFacing.VALUES) {
currentPos.move(facing);
IBlockState blockStateHere = worldIn.getBlockState(currentPos);
// if there is node, and it can connect with previous node, add it to list, and set previous node as current
if (blockStateHere.getBlock() instanceof BlockFrame && currentPos.distanceSq(centerPos) <= maxRadiusSq && (frameState == null || frameState == blockStateHere) && !observedSet.contains(currentPos)) {
BlockPos immutablePos = currentPos.toImmutable();
observedSet.add(immutablePos);
resultFrameBlocks.add(immutablePos);
moveStack.push(facing.getOpposite());
frameState = blockStateHere;
continue main;
} else
currentPos.move(facing.getOpposite());
}
if (!moveStack.isEmpty()) {
currentPos.move(moveStack.pop());
} else
break;
}
resultFrameBlocks.sort(Comparator.comparing(it -> it.distanceSq(centerPos)));
return resultFrameBlocks;
}
use of gregtech.common.blocks.BlockFrame in project GregTech by GregTechCE.
the class FoamSprayerBehavior method foamAllFrameBlocks.
private static int foamAllFrameBlocks(World world, BlockPos pos, int maxBlocksToFoam, boolean isSneaking) {
List<BlockPos> frameBlocks = gatherFrameBlocks(world, pos, 1024);
frameBlocks = frameBlocks.subList(0, Math.min(frameBlocks.size(), maxBlocksToFoam));
// replace blocks without updating physics
for (BlockPos framePos : frameBlocks) {
IBlockState blockState = world.getBlockState(framePos);
boolean isNormalFrame = ModHandler.isMaterialWood(((BlockFrame) blockState.getBlock()).frameMaterial) || isSneaking;
if (isNormalFrame) {
blockState.getBlock().dropBlockAsItem(world, framePos, blockState, 0);
}
IBlockState foamToPlace = isNormalFrame ? MetaBlocks.FOAM.getDefaultState() : MetaBlocks.REINFORCED_FOAM.getDefaultState();
world.setBlockState(framePos, foamToPlace, 2);
}
// perform block physics updates
for (BlockPos blockPos : frameBlocks) {
IBlockState blockState = world.getBlockState(blockPos);
world.notifyNeighborsRespectDebug(blockPos, blockState.getBlock(), true);
}
return frameBlocks.size();
}
use of gregtech.common.blocks.BlockFrame in project GregTech by GregTechCEu.
the class FrameBakedModel method getQuads.
@Override
@Nonnull
public List<BakedQuad> getQuads(@Nullable IBlockState state, @Nullable EnumFacing side, long rand) {
List<BakedQuad> quads = new ArrayList<>();
if (side == null)
return quads;
if (state != null) {
Material material = state.getValue(((BlockFrame) state.getBlock()).variantProperty);
Map<EnumFacing, BakedQuad> materialFace = materialFaces.get(material.getMaterialIconSet());
if (materialFace == null) {
materialFaces.put(material.getMaterialIconSet(), materialFace = new Object2ObjectOpenHashMap<>());
}
BakedQuad materialFaceQuad = materialFace.get(side);
if (materialFaceQuad == null) {
materialFace.put(side, materialFaceQuad = ModelFactory.getBakery().makeBakedQuad(new Vector3f(0F, 0F, 0F), new Vector3f(16F, 16F, 16F), new BlockPartFace(side, 1, "", new BlockFaceUV(new float[] { 0.0F, 0.0F, 16.0F, 16.0F, 0.0F, 0.0F, 16.0F, 16.0F }, 0)), ModelLoader.defaultTextureGetter().apply(MaterialIconType.frameGt.getBlockPath(material.getMaterialIconSet())), side, ModelRotation.X0_Y0, null, true, true));
}
quads.add(materialFaceQuad);
particle.set(materialFaceQuad.getSprite());
} else {
ItemStack stack = FrameModelItemOverride.INSTANCE.stack.get();
if (!stack.isEmpty()) {
BlockFrame frame = (BlockFrame) ((ItemBlock) stack.getItem()).getBlock();
IBlockState frameState = frame.getDefaultState().withProperty(frame.variantProperty, frame.variantProperty.getAllowedValues().get(stack.getMetadata()));
for (EnumFacing face : EnumFacing.VALUES) {
quads.addAll(getQuads(frameState, face, rand));
}
}
}
return quads;
}
use of gregtech.common.blocks.BlockFrame in project GregTech by GregTechCEu.
the class FoamSprayerBehavior method gatherFrameBlocks.
private static List<BlockPos> gatherFrameBlocks(World worldIn, BlockPos centerPos, int maxRadiusSq) {
HashSet<BlockPos> observedSet = new HashSet<>();
ArrayList<BlockPos> resultFrameBlocks = new ArrayList<>();
observedSet.add(centerPos);
resultFrameBlocks.add(centerPos);
IBlockState frameState = null;
Stack<EnumFacing> moveStack = new Stack<>();
MutableBlockPos currentPos = new MutableBlockPos(centerPos);
main: while (true) {
for (EnumFacing facing : EnumFacing.VALUES) {
currentPos.move(facing);
IBlockState blockStateHere = worldIn.getBlockState(currentPos);
// if there is node, and it can connect with previous node, add it to list, and set previous node as current
if (blockStateHere.getBlock() instanceof BlockFrame && currentPos.distanceSq(centerPos) <= maxRadiusSq && (frameState == null || frameState == blockStateHere) && !observedSet.contains(currentPos)) {
BlockPos immutablePos = currentPos.toImmutable();
observedSet.add(immutablePos);
resultFrameBlocks.add(immutablePos);
moveStack.push(facing.getOpposite());
frameState = blockStateHere;
continue main;
} else
currentPos.move(facing.getOpposite());
}
if (!moveStack.isEmpty()) {
currentPos.move(moveStack.pop());
} else
break;
}
resultFrameBlocks.sort(Comparator.comparing(it -> it.distanceSq(centerPos)));
return resultFrameBlocks;
}
use of gregtech.common.blocks.BlockFrame in project GregTech by GregTechCE.
the class FoamSprayerBehavior method onItemUse.
@Override
public ActionResult<ItemStack> onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
ItemStack itemStack = player.getHeldItem(hand);
IFluidHandlerItem fluidHandlerItem = itemStack.getCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, null);
FluidStack fluidStack = fluidHandlerItem.drain(Integer.MAX_VALUE, false);
if (fluidStack != null && fluidStack.amount >= FLUID_PER_BLOCK) {
BlockPos offsetPos = pos.offset(facing);
IBlockState initialBlockState = world.getBlockState(pos);
IBlockState offsetState = world.getBlockState(offsetPos);
if (initialBlockState.getBlock() instanceof BlockFrame) {
int blocksToFoam = fluidStack.amount / FLUID_PER_BLOCK;
int blocksFoamed = foamAllFrameBlocks(world, pos, blocksToFoam, player.isSneaking());
if (!player.capabilities.isCreativeMode) {
fluidHandlerItem.drain(FLUID_PER_BLOCK * blocksFoamed, true);
}
return ActionResult.newResult(EnumActionResult.SUCCESS, itemStack);
} else if (offsetState.getBlock().isReplaceable(world, offsetPos)) {
int blocksToFoam = fluidStack.amount / FLUID_PER_BLOCK;
int blocksFoamed = foamReplacableBlocks(world, offsetPos, blocksToFoam);
if (!player.capabilities.isCreativeMode) {
fluidHandlerItem.drain(FLUID_PER_BLOCK * blocksFoamed, true);
}
return ActionResult.newResult(EnumActionResult.SUCCESS, itemStack);
}
}
return ActionResult.newResult(EnumActionResult.PASS, itemStack);
}
Aggregations