public static void generateSphere(World world, BlockPos center, int radius, ITreeBlockType block, EnumReplaceMode replace) { Vec3i start = new Vec3i(center.getX() - radius, center.getY() - radius, center.getZ() - radius); Vec3i area = new Vec3i(radius * 2 + 1, radius * 2 + 1, radius * 2 + 1); for (int x = start.getX(); x < start.getX() + area.getX(); x++) { for (int y = start.getY() + area.getY() - 1; y >= start.getY(); y--) { // generating top-down is faster for lighting calculations for (int z = start.getZ(); z < start.getZ() + area.getZ(); z++) { if (center.getDistance(x, y, z) <= radius + 0.01) { addBlock(world, new BlockPos(x, y, z), block, replace); } } } } }
@Override public boolean canIntakeFrom(TEBellows te, Vec3i offset, EnumFacing facing) { return offset.equals(bellowsOffset); }
@Override public boolean onBlockStartBreak(ItemStack stack, BlockPos pos, EntityPlayer player) { World world = player.world; Material mat = world.getBlockState(pos).getMaterial(); if (!ToolCommons.materialsShovel.contains(mat)) return false; RayTraceResult block = ToolCommons.raytraceFromEntity(world, player, true, 10); if (block == null) return false; Block blk = world.getBlockState(pos).getBlock(); if(blk instanceof BlockFalling) ToolCommons.removeBlocksInIteration(player, stack, world, pos, new Vec3i(0, -12, 0), new Vec3i(1, 12, 1), state -> state.getBlock() == blk, false); return false; }
private void parseLayer(List<String> templateLines, int yLayer, Vec3i size, short[] templateData) { int z = 0; for (String st : templateLines) { if (st.startsWith("layer:") || st.startsWith(":endlayer")) { continue; } short[] data = StringTools.parseShortArray(st); for (int x = 0; x < size.getX() && x < data.length; x++) { templateData[StructureTemplate.getIndex(new Vec3i(x, yLayer, z), size)] = data[x]; } z++; } }
public void setupStructureBuilder(World world, BlockPos pos, TileStructureBuilder tb, String name, EnumFacing face) { StructureTemplateManager.getTemplate(name).ifPresent(t -> { BlockPos p = pos.offset(face, t.getSize().getZ() - 1 - t.getOffset().getZ() + 1); tb.setBuilder(new StructureBuilderTicked(world, t, face, p)); }); }
throw new IllegalArgumentException("Invalid rotation: " + front + " & " + top); Vec3i frontVec = new Vec3i(front.getFrontOffsetX(), front.getFrontOffsetY(), front.getFrontOffsetZ()); Vec3i topVec = new Vec3i(-top.getFrontOffsetX(), -top.getFrontOffsetY(), -top.getFrontOffsetZ()); Vec3i perpVec = topVec.crossProduct(frontVec); StructureBuilder copy = new StructureBuilder(); copy.front = transform(this.front, frontVec, topVec, perpVec);
@Override public void renderParticle(@Nonnull BufferBuilder buffer, @Nonnull Entity entityIn, float partialTicks, float rotationX, float rotationZ, float rotationYZ, float rotationXY, float rotationXZ) { // Move the particle against the face of the block, and counteract the scaling so that it grows from the center buffer.setTranslation(-0.08 * facing.getDirectionVec().getX() * offset, -particleScale * height, -0.08 * facing.getDirectionVec().getZ() * offset); // Lie about rotation so that it always renders facing outwards from the machine super.renderParticle(buffer, entityIn, partialTicks, facing.getDirectionVec().getZ(), 1, facing.getDirectionVec().getX(), 0, 0); buffer.setTranslation(0, 0, 0); } }
@Override public boolean validatePlacement(World world, int x, int y, int z, EnumFacing face, StructureTemplate template, StructureBB bb) { if (y - template.offset.getY() <= 0) { AncientWarfareStructure.LOG.debug("Ground isn't deep enough for the structure- required: {}, found: {}", Math.abs(bb.min.getY()), y); return false; } int minY = getMinY(template, bb); int maxY = getMaxY(template, bb); return validateBorderBlocks(world, bb, minY, maxY, false); }
case COW_IN_A_JAR: soundEvent = SoundEvents.ENTITY_CHICKEN_EGG; particleOffset = new Vec3i(0, 1, 0); break; case OVEN_UPGRADE: float offsetX = particleOffset.getX() + 0.5f + (float) (Math.random() - 0.5f) * particleRandomOffset; float offsetY = particleOffset.getX() + 0.5f + (float) (Math.random() - 0.5f) * particleRandomOffset; float offsetZ = particleOffset.getX() + 0.5f + (float) (Math.random() - 0.5f) * particleRandomOffset; Minecraft.getMinecraft().world.spawnParticle(particleTypes, true, message.getPos().getX() + offsetX, message.getPos().getY() + offsetY, message.getPos().getZ() + offsetZ, 0f, 0f, 0f);
@Override public int getAdjustedSpawnY(World world, int x, int y, int z, EnumFacing face, StructureTemplate template, StructureBB bb) { testMin = new BlockPos(x, y, z).offset(face, template.getOffset().getZ()); return WorldStructureGenerator.getTargetY(world, testMin.getX(), testMin.getZ(), false) + 1; }
protected Vec3i getModifiedArea(final IBeeGenome genome, final IBeeHousing housing) { Vec3i territory = genome.getTerritory(); territory = new Vec3i( territory.getX() * (int) (BeeManager.beeRoot.createBeeHousingModifier(housing).getTerritoryModifier(genome, 1.0f) * 3.0f), territory.getY() * (int) (BeeManager.beeRoot.createBeeHousingModifier(housing).getTerritoryModifier(genome, 1.0f) * 3.0f), territory.getZ() * (int) (BeeManager.beeRoot.createBeeHousingModifier(housing).getTerritoryModifier(genome, 1.0f) * 3.0f) ); if (territory.getX() < 1) { territory = new Vec3i(1, territory.getY(), territory.getZ()); } if (territory.getY() < 1) { territory = new Vec3i(territory.getX(), 1, territory.getZ()); } if (territory.getZ() < 1) { territory = new Vec3i(territory.getX(), territory.getY(), 1); } return territory; }
private static void renderPreviewAt(StructureTemplate structure, StructureBB bb, int turns, BufferBuilder buffer, Map<BlockPos, TemplateRuleBlock> dynamicRenderRules, TemplateBlockAccess blockAccess, BlockPos pos) { BlockPos translateTo = BlockTools.rotateInArea(pos, structure.getSize().getX(), structure.getSize().getZ(), turns).add(bb.min); structure.getBlockRuleAt(pos).ifPresent(r -> { r.renderRule(turns, translateTo, blockAccess, buffer); if (r.isDynamicallyRendered(turns)) { dynamicRenderRules.put(translateTo, r); } }); }
private static boolean areAllAirInLayer(Vec3i size, int yLayer, short[] templateRuleData) { for (int z = 0; z < size.getZ(); z++) { for (int x = 0; x < size.getX(); x++) { int index = StructureTemplate.getIndex(new Vec3i(x, yLayer, z), size); if (templateRuleData[index] != 0) { return false; } } } return true; } }