use of net.minecraft.block.BlockSapling in project DynamicSurroundings by OreCruncher.
the class FootstepsRegistry method seedMap.
private void seedMap() {
// Iterate through the blockmap looking for known pattern types.
// Though they probably should all be registered with Forge
// dictionary it's not a requirement.
final Iterator<Block> itr = Block.REGISTRY.iterator();
while (itr.hasNext()) {
final Block block = itr.next();
final String blockName = MCHelper.nameOf(block);
if (block instanceof BlockCrops) {
final BlockCrops crop = (BlockCrops) block;
if (crop.getMaxAge() == 3) {
registerBlocks("#beets", blockName);
} else if (blockName.equals("minecraft:wheat")) {
registerBlocks("#wheat", blockName);
} else if (crop.getMaxAge() == 7) {
registerBlocks("#crop", blockName);
}
} else if (block instanceof BlockSapling) {
registerBlocks("#sapling", blockName);
} else if (block instanceof BlockReed) {
registerBlocks("#reed", blockName);
} else if (block instanceof BlockFence) {
registerBlocks("#fence", blockName);
} else if (block instanceof BlockFlower || block instanceof BlockMushroom) {
registerBlocks("NOT_EMITTER", blockName);
} else if (block instanceof BlockLog || block instanceof BlockPlanks) {
registerBlocks("wood", blockName);
} else if (block instanceof BlockDoor) {
registerBlocks("bluntwood", blockName);
} else if (block instanceof BlockLeaves) {
registerBlocks("leaves", blockName);
} else if (block instanceof BlockOre) {
registerBlocks("ore", blockName);
} else if (block instanceof BlockIce) {
registerBlocks("ice", blockName);
}
}
}
use of net.minecraft.block.BlockSapling in project Traverse by ProfessorProspector.
the class TraverseClient method tooltip.
@SubscribeEvent
public void tooltip(RenderTooltipEvent.Pre event) {
boolean render = false;
ItemStack stack = event.getStack();
if (stack.getItem() instanceof ItemBlock) {
if (((ItemBlock) stack.getItem()).getBlock() instanceof BlockSapling)
render = true;
if (((ItemBlock) stack.getItem()).getBlock() instanceof BlockLeaves)
render = true;
if (((ItemBlock) stack.getItem()).getBlock() instanceof BlockFlower)
render = true;
if (((ItemBlock) stack.getItem()).getBlock() instanceof BlockDoublePlant)
render = true;
if (((ItemBlock) stack.getItem()).getBlock() == Blocks.WATERLILY)
render = true;
if (((ItemBlock) stack.getItem()).getBlock() == Blocks.VINE)
render = true;
if (((ItemBlock) stack.getItem()).getBlock() == Blocks.TALLGRASS)
render = true;
if (((ItemBlock) stack.getItem()).getBlock() == Blocks.DEADBUSH)
render = true;
} else {
}
if (!render)
return;
;
event.setCanceled(true);
List<String> textLines = new ArrayList<>();
textLines.addAll(event.getLines());
int mouseX = event.getX();
int mouseY = event.getY();
int screenWidth = event.getScreenWidth();
int screenHeight = event.getScreenHeight();
int maxTextWidth = event.getMaxWidth();
FontRenderer font = event.getFontRenderer();
GlStateManager.disableRescaleNormal();
RenderHelper.disableStandardItemLighting();
GlStateManager.disableLighting();
GlStateManager.disableDepth();
int tooltipTextWidth = 0;
for (String textLine : textLines) {
int textLineWidth = font.getStringWidth(textLine);
if (textLineWidth > tooltipTextWidth) {
tooltipTextWidth = textLineWidth;
}
}
boolean needsWrap = false;
int titleLinesCount = 1;
int tooltipX = mouseX + 12;
if (tooltipX + tooltipTextWidth + 4 > screenWidth) {
tooltipX = mouseX - 16 - tooltipTextWidth;
if (// if the tooltip doesn't fit on the screen
tooltipX < 4) {
if (mouseX > screenWidth / 2) {
tooltipTextWidth = mouseX - 12 - 8;
} else {
tooltipTextWidth = screenWidth - 16 - mouseX;
}
needsWrap = true;
}
}
if (maxTextWidth > 0 && tooltipTextWidth > maxTextWidth) {
tooltipTextWidth = maxTextWidth;
needsWrap = true;
}
if (needsWrap) {
int wrappedTooltipWidth = 0;
List<String> wrappedTextLines = new ArrayList<>();
for (int i = 0; i < textLines.size(); i++) {
String textLine = textLines.get(i);
List<String> wrappedLine = font.listFormattedStringToWidth(textLine, tooltipTextWidth);
if (i == 0) {
titleLinesCount = wrappedLine.size();
}
for (String line : wrappedLine) {
int lineWidth = font.getStringWidth(line);
if (lineWidth > wrappedTooltipWidth) {
wrappedTooltipWidth = lineWidth;
}
wrappedTextLines.add(line);
}
}
tooltipTextWidth = wrappedTooltipWidth;
textLines = wrappedTextLines;
if (mouseX > screenWidth / 2) {
tooltipX = mouseX - 16 - tooltipTextWidth;
} else {
tooltipX = mouseX + 12;
}
}
int tooltipY = mouseY - 12;
int tooltipHeight = 8;
if (textLines.size() > 1) {
tooltipHeight += (textLines.size() - 1) * 10;
if (textLines.size() > titleLinesCount) {
// gap between title lines and next lines
tooltipHeight += 2;
}
}
if (tooltipY + tooltipHeight + 6 > screenHeight) {
tooltipY = screenHeight - tooltipHeight - 6;
}
final int zLevel = 300;
int backgroundX = tooltipX - 3;
int backgroundY = tooltipY - 3;
int backgroundWidth = tooltipTextWidth + 5;
int backgroundHeight = tooltipHeight + 6;
final int backgroundColor = 0xF0100010;
GuiUtils.drawGradientRect(zLevel, tooltipX - 3, tooltipY - 4, tooltipX + tooltipTextWidth + 3, tooltipY - 3, backgroundColor, backgroundColor);
GuiUtils.drawGradientRect(zLevel, tooltipX - 3, tooltipY + tooltipHeight + 3, tooltipX + tooltipTextWidth + 3, tooltipY + tooltipHeight + 4, backgroundColor, backgroundColor);
GuiUtils.drawGradientRect(zLevel, tooltipX - 3, tooltipY - 3, tooltipX + tooltipTextWidth + 3, tooltipY + tooltipHeight + 3, backgroundColor, backgroundColor);
GuiUtils.drawGradientRect(zLevel, tooltipX - 4, tooltipY - 3, tooltipX - 3, tooltipY + tooltipHeight + 3, backgroundColor, backgroundColor);
GuiUtils.drawGradientRect(zLevel, tooltipX + tooltipTextWidth + 3, tooltipY - 3, tooltipX + tooltipTextWidth + 4, tooltipY + tooltipHeight + 3, backgroundColor, backgroundColor);
final int borderColorStart = new Color(0x24B528).getRGB();
final int borderColorEnd = (borderColorStart & 0xFEFEFE) >> 1 | borderColorStart & 0xFF000000;
GuiUtils.drawGradientRect(zLevel, tooltipX - 3, tooltipY - 3 + 1, tooltipX - 3 + 1, tooltipY + tooltipHeight + 3 - 1, borderColorStart, borderColorEnd);
GuiUtils.drawGradientRect(zLevel, tooltipX + tooltipTextWidth + 2, tooltipY - 3 + 1, tooltipX + tooltipTextWidth + 3, tooltipY + tooltipHeight + 3 - 1, borderColorStart, borderColorEnd);
GuiUtils.drawGradientRect(zLevel, tooltipX - 3, tooltipY - 3, tooltipX + tooltipTextWidth + 3, tooltipY - 3 + 1, borderColorStart, borderColorStart);
GuiUtils.drawGradientRect(zLevel, tooltipX - 3, tooltipY + tooltipHeight + 2, tooltipX + tooltipTextWidth + 3, tooltipY + tooltipHeight + 3, borderColorEnd, borderColorEnd);
int tooltipTop = tooltipY;
for (int lineNumber = 0; lineNumber < textLines.size(); ++lineNumber) {
String line = textLines.get(lineNumber);
font.drawStringWithShadow(line, tooltipX, tooltipY, -1);
if (lineNumber + 1 == titleLinesCount) {
tooltipY += 2;
}
tooltipY += 10;
}
MinecraftForge.EVENT_BUS.post(new RenderTooltipEvent.PostText(event.getStack(), textLines, tooltipX, tooltipTop, font, tooltipTextWidth, tooltipHeight));
GlStateManager.enableLighting();
GlStateManager.enableDepth();
RenderHelper.enableStandardItemLighting();
GlStateManager.enableRescaleNormal();
}
use of net.minecraft.block.BlockSapling in project BiomeTweaker by superckl.
the class WorldGenGenericTree method generate.
@Override
public boolean generate(final World world, final Random rand, final BlockPos position) {
final int height = (this.heightVariation == 0 ? 0 : rand.nextInt(this.heightVariation)) + this.minHeight;
boolean shouldGrow = true;
if (position.getY() >= 1 && position.getY() + height + 1 <= world.getHeight()) {
for (int y = position.getY(); y <= position.getY() + 1 + height; ++y) {
int radius = 1;
if (y == position.getY())
radius = 0;
if (y >= position.getY() + 1 + height - 2)
radius = 2;
final BlockPos.MutableBlockPos mutableBlockPos = new BlockPos.MutableBlockPos();
for (int x = position.getX() - radius; x <= position.getX() + radius && shouldGrow; ++x) for (int z = position.getZ() - radius; z <= position.getZ() + radius && shouldGrow; ++z) if (y >= 0 && y < world.getHeight()) {
if (!this.isReplaceable(world, mutableBlockPos.setPos(x, y, z)))
shouldGrow = false;
} else
shouldGrow = false;
}
if (!shouldGrow)
return false;
else {
IBlockState block = world.getBlockState(position.down());
shouldGrow = false;
if (this.soilPredicate == null)
shouldGrow = this.checkCanGrow && block.getBlock().canSustainPlant(block, world, position.down(), EnumFacing.UP, (BlockSapling) Blocks.SAPLING);
else {
shouldGrow = this.soilPredicate.apply(block);
if (shouldGrow == false)
shouldGrow = this.checkCanGrow && block.getBlock().canSustainPlant(block, world, position.down(), EnumFacing.UP, (BlockSapling) Blocks.SAPLING);
}
if (shouldGrow && position.getY() < world.getHeight() - height - 1) {
if (this.checkCanGrow)
block.getBlock().onPlantGrow(block, world, position.down(), position);
for (int y = position.getY() - (this.leafHeight - 1) + height; y <= position.getY() + height; ++y) {
final int ly = y - (position.getY() + height);
final int leafRadius = 1 - ly / 2;
for (int x = position.getX() - leafRadius; x <= position.getX() + leafRadius; ++x) {
final int lx = x - position.getX();
for (int z = position.getZ() - leafRadius; z <= position.getZ() + leafRadius; ++z) {
final int lz = z - position.getZ();
if (Math.abs(lx) != leafRadius || Math.abs(lz) != leafRadius || rand.nextInt(2) != 0 && ly != 0) {
final BlockPos blockpos = new BlockPos(x, y, z);
block = world.getBlockState(blockpos);
if (block.getBlock().isAir(block, world, blockpos) || (this.leafBlock.getBlock().isLeaves(block, world, blockpos) && block.getBlock().isLeaves(block, world, blockpos)) || this.leafPredicate.apply(block) || block.getMaterial() == Material.VINE)
this.setBlockAndNotifyAdequately(world, blockpos, this.leafBlock);
}
}
}
}
for (int y = 0; y < height; ++y) {
final BlockPos up = position.up(y);
block = world.getBlockState(up);
if (block.getBlock().isAir(block, world, up) || (this.leafBlock.getBlock().isLeaves(block, world, up) && block.getBlock().isLeaves(block, world, up)) || this.leafPredicate.apply(block) || block.getMaterial() == Material.VINE) {
this.setBlockAndNotifyAdequately(world, position.up(y), this.trunkBlock);
if (this.growVines && y > 0) {
if (rand.nextInt(3) > 0 && world.isAirBlock(position.add(-1, y, 0)))
this.addVine(world, position.add(-1, y, 0), BlockVine.EAST);
if (rand.nextInt(3) > 0 && world.isAirBlock(position.add(1, y, 0)))
this.addVine(world, position.add(1, y, 0), BlockVine.WEST);
if (rand.nextInt(3) > 0 && world.isAirBlock(position.add(0, y, -1)))
this.addVine(world, position.add(0, y, -1), BlockVine.SOUTH);
if (rand.nextInt(3) > 0 && world.isAirBlock(position.add(0, y, 1)))
this.addVine(world, position.add(0, y, 1), BlockVine.NORTH);
}
}
}
if (this.growVines)
for (int y = position.getY() - 3 + height; y <= position.getY() + height; ++y) {
final int ly = y - (position.getY() + height);
final int vineRadius = 2 - ly / 2;
final BlockPos.MutableBlockPos mutableBlockPos = new BlockPos.MutableBlockPos();
for (int x = position.getX() - vineRadius; x <= position.getX() + vineRadius; ++x) for (int z = position.getZ() - vineRadius; z <= position.getZ() + vineRadius; ++z) {
mutableBlockPos.setPos(x, y, z);
block = world.getBlockState(mutableBlockPos);
if (block.getBlock().isLeaves(block, world, mutableBlockPos)) {
final BlockPos west = mutableBlockPos.west();
final BlockPos east = mutableBlockPos.east();
final BlockPos north = mutableBlockPos.north();
final BlockPos south = mutableBlockPos.south();
if (rand.nextInt(4) == 0 && world.isAirBlock(west))
this.addHangingVine(world, west, BlockVine.EAST);
if (rand.nextInt(4) == 0 && world.isAirBlock(east))
this.addHangingVine(world, east, BlockVine.WEST);
if (rand.nextInt(4) == 0 && world.isAirBlock(north))
this.addHangingVine(world, north, BlockVine.SOUTH);
if (rand.nextInt(4) == 0 && world.isAirBlock(south))
this.addHangingVine(world, south, BlockVine.NORTH);
}
}
}
return true;
} else
return false;
}
} else
return false;
}
use of net.minecraft.block.BlockSapling in project BiomesOPlenty by Glitchfiend.
the class GeneratorBigTree method checkLocation.
private boolean checkLocation() {
BlockPos down = this.origin.down();
IBlockState state = this.world.getBlockState(down);
boolean isSoil = state.getBlock().canSustainPlant(state, this.world, down, EnumFacing.UP, ((BlockSapling) Blocks.SAPLING));
// Don't grow the tree here if the location can't sustain a sapling
if (!isSoil && !this.placeOn.matches(world, down)) {
return false;
}
// Examine center column for how tall the tree can be.
int allowedHeight = checkLine(this.origin, this.origin.up(height - 1));
if (trunkWidth == 2) {
allowedHeight = Math.min(checkLine(this.origin.east(), this.origin.east().up(height - 1)), allowedHeight);
allowedHeight = Math.min(checkLine(this.origin.east().south(), this.origin.east().south().up(height - 1)), allowedHeight);
allowedHeight = Math.min(checkLine(this.origin.south(), this.origin.south().up(height - 1)), allowedHeight);
}
// If the set height is good, go with that
if (allowedHeight == -1) {
return true;
}
// If the space is too short, tell the build to abort
if (allowedHeight < this.minHeight) {
return false;
}
height = allowedHeight;
return true;
}
use of net.minecraft.block.BlockSapling in project Realistic-Terrain-Generation by Team-RTG.
the class EventHandlerCommon method saplingGrowTreeRTG.
// TERRAIN_GEN_BUS
@SuppressWarnings("deprecation")
@SubscribeEvent
public static void saplingGrowTreeRTG(SaplingGrowTreeEvent event) {
final World world = event.getWorld();
// skip if RTG saplings are disabled or this world does not use BiomeProviderRTG
if (!RTGConfig.rtgTreesFromSaplings() || !(world.getBiomeProvider() instanceof BiomeProviderRTG)) {
Logger.debug("[SaplingGrowTreeEvent] Aborting: RTG trees are disabled, or not an RTG dimension");
return;
}
final BlockPos pos = event.getPos();
final IBlockState saplingBlock = world.getBlockState(pos);
Logger.trace("Handling SaplingGrowTreeEvent in dim: {}, at: {}, for: {}", world.provider.getDimension(), pos, saplingBlock);
// Are we dealing with a sapling? Sounds like a silly question, but apparently it's one that needs to be asked.
if (!(saplingBlock.getBlock() instanceof BlockSapling)) {
Logger.debug("[SaplingGrowTreeEvent] Aborting: Sapling is not a sapling block ({})", saplingBlock.getBlock().getClass().getName());
return;
}
final Random rand = event.getRand();
// Should we generate a vanilla tree instead?
int chance = RTGConfig.rtgTreeChance();
if (rand.nextInt(chance < 1 ? 1 : chance) != 0) {
Logger.debug("[SaplingGrowTreeEvent] Aborting RTG tree generation: random chance");
return;
}
final IRealisticBiome rtgBiome = RTGAPI.getRTGBiome(world.getBiome(pos));
Collection<TreeRTG> biomeTrees = rtgBiome.getTrees();
if (biomeTrees.isEmpty()) {
Logger.debug("[SaplingGrowTreeEvent] Aborting RTG tree generation: No RTG trees to generate in Biome: {}", rtgBiome.baseBiomeResLoc());
return;
}
// First, let's get all of the trees in this biome that match the sapling on the ground.
List<TreeRTG> validTrees = biomeTrees.stream().filter(tree -> saplingBlock.getBlock() == tree.getSaplingBlock().getBlock() && BlockUtil.getTypeFromSapling(saplingBlock) == BlockUtil.getTypeFromSapling(tree.getSaplingBlock())).collect(Collectors.toList());
// Abort if there are no valid trees.
if (validTrees.isEmpty()) {
Logger.debug("[SaplingGrowTreeEvent] No RTG trees found for sapling, so generating original tree instead");
return;
}
// Get a random tree from the list of valid trees.
TreeRTG tree = validTrees.get(rand.nextInt(validTrees.size()));
// Set the trunk size if min/max values have been set.
if (tree.getMinTrunkSize() > 0 && tree.getMaxTrunkSize() > tree.getMinTrunkSize()) {
tree.setTrunkSize(DecoBase.getRangedRandom(rand, tree.getMinTrunkSize(), tree.getMaxTrunkSize()));
}
// Set the crown size if min/max values have been set.
if (tree.getMinCrownSize() > 0 && tree.getMaxCrownSize() > tree.getMinCrownSize()) {
tree.setCrownSize(DecoBase.getRangedRandom(rand, tree.getMinCrownSize(), tree.getMaxCrownSize()));
}
int treeHeight = tree.getTrunkSize() + tree.getCrownSize();
if (treeHeight < 1) {
Logger.debug("[SaplingGrowTreeEvent] Unable to grow RTG tree with no height: {}[logblock={}, leafblock={}, saplingblock={}]", tree.getClass().getSimpleName(), tree.getLogBlock(), tree.getLeavesBlock(), tree.getSaplingBlock());
return;
}
if (!BlockUtil.checkVerticalMaterials(BlockUtil.MatchType.ALL_IGNORE_REPLACEABLE, world, pos.up(), treeHeight - 1)) {
Logger.debug("[SaplingGrowTreeEvent] Aborting RTG tree generation: not enough space above");
return;
}
/*
* Set the generateFlag to what it needs to be for growing trees from saplings,
* generate the tree, and then set it back to what it was before.
*
* TODO: Does this affect the generation of normal RTG trees? - Pink
*/
int oldFlag = tree.getGenerateFlag();
tree.setGenerateFlag(3);
boolean generated = tree.generate(world, rand, pos);
tree.setGenerateFlag(oldFlag);
if (generated) {
event.setResult(Event.Result.DENY);
// Sometimes we have to remove the sapling manually because some trees grow around it, leaving the original sapling.
if (world.getBlockState(pos) == saplingBlock) {
world.setBlockState(pos, Blocks.AIR.getDefaultState(), 2);
}
}
Logger.trace("Finished handling SaplingGrowTreeEvent in Biome: {}, with sapling: {}", rtgBiome.baseBiomeResLoc(), saplingBlock);
}
Aggregations