Java Code Examples for net.minecraft.block.Block#getDefaultState()
The following examples show how to use
net.minecraft.block.Block#getDefaultState() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GTOreGenerator.java From GT-Classic with GNU Lesser General Public License v3.0 | 6 votes |
/** rare ore generator **/ public static void generateRareVein(Block block, boolean generate, int blockAmount, int chancesToSpawn, int minHeight, int maxHeight, Block blockToReplace, World world, Random rand, int chunkX, int chunkZ) { if (generate) { WorldGenMinable generator = new WorldGenMinable(block.getDefaultState(), blockAmount, BlockMatcher.forBlock(blockToReplace)); int heightdiff = maxHeight - minHeight + 1; for (int i = 0; i < chancesToSpawn; i++) { int var1 = rand.nextInt(1024); if (var1 == 0) { int x = chunkX * 16 + rand.nextInt(16); int y = minHeight + rand.nextInt(heightdiff); int z = chunkZ * 16 + rand.nextInt(16); generator.generate(world, rand, new BlockPos(x, y, z)); } } } }
Example 2
Source File: EvalExpandModel.java From OpenModsLib with MIT License | 6 votes |
@Override public IBakedModel bake(IModelState state, VertexFormat format, Function<ResourceLocation, TextureAtlasSprite> bakedTextureGetter) { final IModel model = loadBaseModel(state, format, bakedTextureGetter); IBlockState blockState = null; if (defaultBlockState.isPresent()) { final Block defaultBlock = Block.REGISTRY.getObject(defaultBlockState.get()); if (defaultBlock != Blocks.AIR) { blockState = defaultBlock.getDefaultState(); if (!(blockState instanceof IExtendedBlockState) || !((IExtendedBlockState)blockState).getUnlistedNames().contains(EvalModelState.PROPERTY)) { Log.warn("State %s does not contain eval state property", blockState); } } else { Log.warn("Can't find default block: %s", defaultBlockState.get()); } } final IVarExpander expander = evaluatorFactory.createExpander(); return new BakedEvalExpandModel(model, state, format, bakedTextureGetter, blockState, expander); }
Example 3
Source File: GTOreGenerator.java From GT-Classic with GNU Lesser General Public License v3.0 | 6 votes |
public static void generateBedrockVein(Block block, World world, Random rand, int chunkX, int chunkZ) { GTBedrockOreMineable generator = new GTBedrockOreMineable(block.getDefaultState(), GTConfig.generation.bedrockOreSize, BlockMatcher.forBlock(Blocks.BEDROCK)); int minHeight = 0; int maxHeight = 10; int heightdiff = maxHeight - minHeight + 1; int chance = 8192; for (int i = 0; i < GTConfig.generation.bedrockOreWeight; i++) { int var1 = rand.nextInt(chance); if (var1 == 0) { int x = chunkX * 16 + rand.nextInt(16); int y = 0 + rand.nextInt(heightdiff); int z = chunkZ * 16 + rand.nextInt(16); generator.generate(world, rand, new BlockPos(x, y, z)); } } }
Example 4
Source File: CoralBlockMixin.java From fabric-carpet with MIT License | 5 votes |
public void grow(ServerWorld worldIn, Random random, BlockPos pos, BlockState blockUnder) { CoralFeature coral; int variant = random.nextInt(3); if (variant == 0) coral = new CoralClawFeature(DefaultFeatureConfig::deserialize); else if (variant == 1) coral = new CoralTreeFeature(DefaultFeatureConfig::deserialize); else coral = new CoralMushroomFeature(DefaultFeatureConfig::deserialize); MaterialColor color = blockUnder.getTopMaterialColor(worldIn, pos); BlockState proper_block = blockUnder; for (Block block: BlockTags.CORAL_BLOCKS.values()) { proper_block = block.getDefaultState(); if (proper_block.getTopMaterialColor(worldIn,pos) == color) { break; } } worldIn.setBlockState(pos, Blocks.WATER.getDefaultState(), 4); if (!((CoralFeatureInterface)coral).growSpecific(worldIn, random, pos, proper_block)) { worldIn.setBlockState(pos, blockUnder, 3); } else { if (worldIn.random.nextInt(10)==0) { BlockPos randomPos = pos.add(worldIn.random.nextInt(16)-8,worldIn.random.nextInt(8),worldIn.random.nextInt(16)-8 ); if (BlockTags.CORAL_BLOCKS.contains(worldIn.getBlockState(randomPos).getBlock())) { worldIn.setBlockState(randomPos, Blocks.WET_SPONGE.getDefaultState(), 3); } } } }
Example 5
Source File: GTOreGenerator.java From GT-Classic with GNU Lesser General Public License v3.0 | 5 votes |
/** default ore generator **/ public static void generateBasicVein(Block block, boolean generate, int blockAmount, int chancesToSpawn, int minHeight, int maxHeight, Block blockToReplace, World world, Random rand, int chunkX, int chunkZ) { if (generate) { WorldGenMinable generator = new WorldGenMinable(block.getDefaultState(), blockAmount, BlockMatcher.forBlock(blockToReplace)); int heightdiff = maxHeight - minHeight + 1; for (int i = 0; i < chancesToSpawn; i++) { int x = chunkX * 16 + rand.nextInt(16); int y = minHeight + rand.nextInt(heightdiff); int z = chunkZ * 16 + rand.nextInt(16); generator.generate(world, rand, new BlockPos(x, y, z)); } } }
Example 6
Source File: WrappedBlockStateImpl.java From customstuff4 with GNU General Public License v3.0 | 5 votes |
@Override @SuppressWarnings("unchecked") public IBlockState createState() { Block block = getBlock(); if (block != null) { IBlockState state = block.getDefaultState(); for (Tuple<String, String> tuple : properties) { String name = tuple.getFirst(); Optional<IProperty> prop = getProperty(state, name); if (prop.isPresent()) { IProperty property = prop.get(); state = state.withProperty(property, (Comparable) property.parseValue(tuple.getSecond()).get()); } } return state; } else { return null; } }
Example 7
Source File: MinecraftTypeHelper.java From malmo with MIT License | 5 votes |
/** * Attempts to parse the block type string. * @param s The string to parse. * @return The block type, or null if the string is not recognised. */ public static IBlockState ParseBlockType( String s ) { if( s == null ) return null; Block block = (Block)Block.REGISTRY.getObject(new ResourceLocation( s )); if( block instanceof BlockAir && !s.equals("air") ) // Minecraft returns BlockAir when it doesn't recognise the string return null; // unrecognised string return block.getDefaultState(); }
Example 8
Source File: SnakeDecoratorImplementation.java From malmo with MIT License | 5 votes |
public SnakeDecoratorImplementation() { Block fresh = (Block)Block.REGISTRY.getObject(new ResourceLocation(this.freshBlockName)); Block stale = (Block)Block.REGISTRY.getObject(new ResourceLocation(this.staleBlockName)); this.freshBlock = (fresh != null) ? fresh.getDefaultState() : Blocks.GLOWSTONE.getDefaultState(); this.staleBlock = (stale != null) ? stale.getDefaultState() : Blocks.AIR.getDefaultState(); }
Example 9
Source File: TunnellerHack.java From Wurst7 with GNU General Public License v3.0 | 5 votes |
private boolean equipSolidBlock(BlockPos pos) { for(int slot = 0; slot < 9; slot++) { // filter out non-block items ItemStack stack = MC.player.inventory.getStack(slot); if(stack.isEmpty() || !(stack.getItem() instanceof BlockItem)) continue; Block block = Block.getBlockFromItem(stack.getItem()); // filter out non-solid blocks BlockState state = block.getDefaultState(); if(!state.isFullCube(EmptyBlockView.INSTANCE, BlockPos.ORIGIN)) continue; // filter out blocks that would fall if(block instanceof FallingBlock && FallingBlock .canFallThrough(BlockUtils.getState(pos.down()))) continue; MC.player.inventory.selectedSlot = slot; return true; } return false; }
Example 10
Source File: DummyBlock.java From multiconnect with MIT License | 4 votes |
DummyBlock(Block original) { this(original.getDefaultState()); }
Example 11
Source File: BlockInfo.java From GregTech with GNU Lesser General Public License v3.0 | 4 votes |
public BlockInfo(Block block) { this(block.getDefaultState()); }
Example 12
Source File: ScaffoldWalkHack.java From Wurst7 with GNU General Public License v3.0 | 4 votes |
@Override public void onUpdate() { BlockPos belowPlayer = new BlockPos(MC.player.getPos()).down(); // check if block is already placed if(!BlockUtils.getState(belowPlayer).getMaterial().isReplaceable()) return; // search blocks in hotbar int newSlot = -1; for(int i = 0; i < 9; i++) { // filter out non-block items ItemStack stack = MC.player.inventory.getStack(i); if(stack.isEmpty() || !(stack.getItem() instanceof BlockItem)) continue; // filter out non-solid blocks Block block = Block.getBlockFromItem(stack.getItem()); BlockState state = block.getDefaultState(); if(!state.isFullCube(EmptyBlockView.INSTANCE, BlockPos.ORIGIN)) continue; // filter out blocks that would fall if(block instanceof FallingBlock && FallingBlock .canFallThrough(BlockUtils.getState(belowPlayer.down()))) continue; newSlot = i; break; } // check if any blocks were found if(newSlot == -1) return; // set slot int oldSlot = MC.player.inventory.selectedSlot; MC.player.inventory.selectedSlot = newSlot; placeBlock(belowPlayer); // reset slot MC.player.inventory.selectedSlot = oldSlot; }
Example 13
Source File: HallowedStairsBlock.java From the-hallow with MIT License | 4 votes |
public HallowedStairsBlock(Block base, Settings settings) { this(base.getDefaultState(), settings); }
Example 14
Source File: StructureBuilder.java From mobycraft with Apache License 2.0 | 4 votes |
public static void replace(World world, BlockPos start, BlockPos end, Block blockToReplace, Block blockToReplaceWith) { int startX = start.getX(); int endX = end.getX(); int startY = start.getY(); int endY = end.getY(); int startZ = start.getZ(); int endZ = end.getZ(); int[] intSwitchArray = new int[2]; if (endX < startX) { intSwitchArray = switchNumbers(startX, endX); startX = intSwitchArray[0]; endX = intSwitchArray[1]; } if (endY < startY) { intSwitchArray = switchNumbers(startY, endY); startY = intSwitchArray[0]; endY = intSwitchArray[1]; } if (endZ < startZ) { intSwitchArray = switchNumbers(startZ, endZ); startZ = intSwitchArray[0]; endZ = intSwitchArray[1]; } for (int x = startX; x < endX + 1; x++) { for (int y = startY; y < endY + 1; y++) { for (int z = startZ; z < endZ + 1; z++) { if (world.getBlockState(new BlockPos(x, y, z)) == blockToReplace .getDefaultState()) { world.setBlockState(new BlockPos(x, y, z), blockToReplaceWith.getDefaultState()); } } } } }
Example 15
Source File: FluidRecipeLoader.java From Wizardry with GNU Lesser General Public License v3.0 | 4 votes |
private static Set<BlockPos> allLiquidInPool(World world, BlockPos pos, int needed, Fluid fluid) { if (needed <= 0) return Sets.newHashSet(); Block block = fluid.getBlock(); if (block == null) return Sets.newHashSet(); IBlockState sourceBlock = block.getDefaultState(); BlockPos.MutableBlockPos topPos = new BlockPos.MutableBlockPos(pos); IBlockState stateAt = world.getBlockState(topPos); boolean lastWasFluid = false; while (stateAt.getBlock() == block) { lastWasFluid = stateAt == sourceBlock; stateAt = world.getBlockState(topPos.setPos(topPos.getX(), topPos.getY() + 1, topPos.getZ())); } topPos.setPos(topPos.getX(), topPos.getY() - 1, topPos.getZ()); BlockPos.MutableBlockPos tool = new BlockPos.MutableBlockPos(); Set<BlockPos> positions = Sets.newHashSet(topPos.toImmutable()); Set<BlockPos> visited = Sets.newHashSet(positions); Set<BlockPos> resultants = Sets.newHashSet(); if (lastWasFluid) resultants.addAll(positions); while (resultants.size() < needed && !positions.isEmpty() && visited.size() < 1000) { BlockPos point = positions.iterator().next(); positions.remove(point); for (int index = EnumFacing.VALUES.length - 1; index >= 0; index--) { EnumFacing facing = EnumFacing.byIndex(index); tool.setPos(point.getX() + facing.getXOffset(), point.getY() + facing.getYOffset(), point.getZ() + facing.getZOffset()); if (!visited.contains(tool)) { BlockPos immutable = tool.toImmutable(); visited.add(immutable); stateAt = world.getBlockState(tool); if (stateAt.getBlock() == block) { positions.add(immutable); if (stateAt == sourceBlock) { resultants.add(immutable); if (resultants.size() >= needed) return resultants; } } } } } return resultants; }
Example 16
Source File: CraftingHelper.java From malmo with MIT License | 4 votes |
/** * Little utility method for dumping out a list of all the Minecraft items, plus as many useful attributes as * we can find for them. This is primarily used by decision_tree_test.py but might be useful for real-world applications too. * * @param filename location to save the dumped list. * @throws IOException */ public static void dumpItemProperties(String filename) throws IOException { FileOutputStream fos = new FileOutputStream("..//..//build//install//Python_Examples//item_database.json"); OutputStreamWriter osw = new OutputStreamWriter(fos, "utf-8"); BufferedWriter writer = new BufferedWriter(osw); JsonArray itemTypes = new JsonArray(); for (ResourceLocation i : Item.REGISTRY.getKeys()) { Item item = Item.REGISTRY.getObject(i); if (item != null) { JsonObject json = new JsonObject(); json.addProperty("type", Item.REGISTRY.getNameForObject(item).toString().replace("minecraft:", "")); json.addProperty("damageable", item.isDamageable()); json.addProperty("rendersIn3D", item.isFull3D()); json.addProperty("repairable", item.isRepairable()); CreativeTabs tab = item.getCreativeTab(); json.addProperty("tab", ((tab != null) ? item.getCreativeTab().getTabLabel() : "none")); ItemStack is = item.getDefaultInstance(); json.addProperty("stackable", is.isStackable()); json.addProperty("enchantable", is.isItemEnchantable()); json.addProperty("rare", (is.getRarity() == EnumRarity.RARE)); // Enum has four types, but only two (COMMON and RARE) appear to be used. json.addProperty("action", is.getItemUseAction().toString()); json.addProperty("hasSubtypes", item.getHasSubtypes()); json.addProperty("maxDamage", is.getMaxDamage()); json.addProperty("maxUseDuration", is.getMaxItemUseDuration()); json.addProperty("block", item instanceof ItemBlock); json.addProperty("hasContainerItem", item.hasContainerItem()); if (item instanceof ItemBlock) { ItemBlock ib = (ItemBlock) item; Block b = ib.getBlock(); IBlockState bs = b.getDefaultState(); json.addProperty("slipperiness", b.slipperiness); json.addProperty("hardness", bs.getBlockHardness(null, null)); json.addProperty("causesSuffocation", bs.causesSuffocation()); json.addProperty("canProvidePower", bs.canProvidePower()); json.addProperty("translucent", bs.isTranslucent()); Material mat = bs.getMaterial(); if (mat != null) { json.addProperty("canBurn", mat.getCanBurn()); json.addProperty("isLiquid", mat.isLiquid()); json.addProperty("blocksMovement", mat.blocksMovement()); json.addProperty("needsNoTool", mat.isToolNotRequired()); json.addProperty("isReplaceable", mat.isReplaceable()); json.addProperty("pistonPushable", mat.getMobilityFlag() == EnumPushReaction.NORMAL); json.addProperty("woodenMaterial", mat == Material.WOOD); json.addProperty("ironMaterial", mat == Material.IRON); json.addProperty("glassyMaterial", mat == Material.GLASS); json.addProperty("clothMaterial", mat == Material.CLOTH); } boolean hasDirection = false; boolean hasColour = false; boolean hasVariant = false; for (IProperty prop : bs.getProperties().keySet()) { System.out.println(Item.REGISTRY.getNameForObject(item).toString() + " -- " + prop); if (prop instanceof PropertyDirection) hasDirection = true; if (prop instanceof PropertyEnum && prop.getName().equals("color")) hasColour = true; if (prop instanceof PropertyEnum && prop.getName().equals("variant")) { hasVariant = true; json.addProperty("variant", bs.getValue(prop).toString()); } } json.addProperty("hasDirection", hasDirection); json.addProperty("hasColour", hasColour); json.addProperty("hasVariant", hasVariant); } itemTypes.add(json); } } writer.write(itemTypes.toString()); writer.close(); }
Example 17
Source File: WorldGenElectricMushroom.java From AdvancedRocketry with MIT License | 4 votes |
public WorldGenElectricMushroom(Block block) { state = block.getDefaultState(); }