generated from Turnip-Labs/bta-example-mod
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Rin
committed
Nov 27, 2024
1 parent
6be92e6
commit d9c9eff
Showing
48 changed files
with
541 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
src/main/java/mizurin/shieldmod/WorldFeatureTreeApple.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package mizurin.shieldmod; | ||
import mizurin.shieldmod.blocks.RinBlocks; | ||
import net.minecraft.core.world.World; | ||
import net.minecraft.core.world.generate.feature.tree.WorldFeatureTree; | ||
import net.minecraft.core.world.season.Seasons; | ||
|
||
import java.util.Random; | ||
|
||
public class WorldFeatureTreeApple extends WorldFeatureTree { | ||
public WorldFeatureTreeApple(int leavesID, int logID, int heightMod) { | ||
super(leavesID, logID, heightMod); | ||
} | ||
|
||
public void placeLeaves(World world, int x, int y, int z, Random rand) { | ||
if (rand.nextInt(5) == 0) { | ||
world.setBlockAndMetadataWithNotify(x, y, z, RinBlocks.leavesAppleFlowering.id, world.seasonManager.getCurrentSeason() == Seasons.OVERWORLD_FALL ? 1 : 0); | ||
} else { | ||
world.setBlockWithNotify(x, y, z, RinBlocks.leavesApple.id); | ||
} | ||
|
||
} | ||
|
||
public boolean isLeaf(int id) { | ||
return id == RinBlocks.leavesAppleFlowering.id || id == RinBlocks.leavesApple.id; | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
src/main/java/mizurin/shieldmod/blocks/BlockLeavesApple.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package mizurin.shieldmod.blocks; | ||
|
||
import java.util.Random; | ||
|
||
import net.minecraft.core.block.Block; | ||
import net.minecraft.core.block.BlockLeavesBase; | ||
import net.minecraft.core.block.material.Material; | ||
import net.minecraft.core.world.World; | ||
import net.minecraft.core.world.season.Seasons; | ||
|
||
public class BlockLeavesApple extends BlockLeavesBase { | ||
public BlockLeavesApple(String key, int id) { | ||
super(key, id, Material.leaves); | ||
} | ||
|
||
public void randomDisplayTick(World world, int x, int y, int z, Random rand) { | ||
if (world.getSeasonManager().getCurrentSeason() != null && world.getSeasonManager().getCurrentSeason() == Seasons.OVERWORLD_FALL && rand.nextInt(40) == 0) { | ||
world.spawnParticle("fallingleaf", (double)x, (double)y - 0.10000000149011612, (double)z, 0.0, 0.0, 0.0, 0); | ||
} | ||
|
||
} | ||
|
||
protected Block getSapling() { | ||
return RinBlocks.saplingApple; | ||
} | ||
} |
89 changes: 89 additions & 0 deletions
89
src/main/java/mizurin/shieldmod/blocks/BlockLeavesAppleFlowering.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package mizurin.shieldmod.blocks; | ||
|
||
import java.util.Random; | ||
|
||
import net.minecraft.core.block.BlockLeavesCherry; | ||
import net.minecraft.core.block.entity.TileEntity; | ||
import net.minecraft.core.entity.player.EntityPlayer; | ||
import net.minecraft.core.enums.EnumDropCause; | ||
import net.minecraft.core.item.IBonemealable; | ||
import net.minecraft.core.item.Item; | ||
import net.minecraft.core.item.ItemStack; | ||
import net.minecraft.core.util.helper.Side; | ||
import net.minecraft.core.world.World; | ||
import net.minecraft.core.world.season.Seasons; | ||
|
||
import static mizurin.shieldmod.blocks.RinBlocks.leavesAppleFlowering; | ||
|
||
public class BlockLeavesAppleFlowering extends BlockLeavesCherry implements IBonemealable { | ||
public BlockLeavesAppleFlowering(String key, int id) { | ||
super(key, id); | ||
} | ||
|
||
public ItemStack[] getBreakResult(World world, EnumDropCause dropCause, int x, int y, int z, int meta, TileEntity tileEntity) { | ||
int growthRate = (meta & 240) >> 4; | ||
if (dropCause != EnumDropCause.PICK_BLOCK && dropCause != EnumDropCause.SILK_TOUCH) { | ||
return growthRate == 0 ? null : new ItemStack[]{new ItemStack(Item.foodApple, world.rand.nextInt(2) + 1)}; | ||
} else { | ||
return new ItemStack[]{new ItemStack(this)}; | ||
} | ||
} | ||
|
||
public void onBlockLeftClicked(World world, int x, int y, int z, EntityPlayer player, Side side, double xHit, double yHit) { | ||
this.onBlockRightClicked(world, x, y, z, player, (Side)null, 0.0, 0.0); | ||
} | ||
|
||
public boolean onBlockRightClicked(World world, int x, int y, int z, EntityPlayer player, Side side, double xPlaced, double yPlaced) { | ||
int meta = world.getBlockMetadata(x, y, z); | ||
int decayData = meta & 15; | ||
int growthRate = (meta & 240) >> 4; | ||
if (growthRate > 0) { | ||
world.playSoundAtEntity(player, player, "random.pop", 0.2F, 0.5F); | ||
if (!world.isClientSide) { | ||
this.dropBlockWithCause(world, EnumDropCause.WORLD, x, y, z, meta, (TileEntity)null); | ||
} | ||
|
||
world.setBlockMetadataWithNotify(x, y, z, decayData); | ||
world.scheduleBlockUpdate(x, y, z, leavesAppleFlowering.id, this.tickRate()); | ||
return true; | ||
} else { | ||
return super.onBlockRightClicked(world, x, y, z, player, side, xPlaced, yPlaced); | ||
} | ||
} | ||
|
||
public void updateTick(World world, int x, int y, int z, Random rand) { | ||
super.updateTick(world, x, y, z, rand); | ||
int meta = world.getBlockMetadata(x, y, z); | ||
int growthRate = (meta & 240) >> 4; | ||
if (world.getSeasonManager().getCurrentSeason() == Seasons.OVERWORLD_FALL) { | ||
if (rand.nextInt(20) == 0 && growthRate == 0) { | ||
world.setBlockMetadataWithNotify(x, y, z, 16 | meta); | ||
world.scheduleBlockUpdate(x, y, z, leavesAppleFlowering.id, this.tickRate()); | ||
} | ||
} else if (growthRate > 0) { | ||
world.setBlockMetadataWithNotify(x, y, z, meta & 15); | ||
world.scheduleBlockUpdate(x, y, z, leavesAppleFlowering.id, this.tickRate()); | ||
} | ||
|
||
} | ||
|
||
public boolean onBonemealUsed(ItemStack itemstack, EntityPlayer entityplayer, World world, int blockX, int blockY, int blockZ, Side side, double xPlaced, double yPlaced) { | ||
int meta = world.getBlockMetadata(blockX, blockY, blockZ); | ||
if ((meta & 240) >> 4 == 0) { | ||
if (!world.isClientSide) { | ||
if (world.getSeasonManager().getCurrentSeason() != Seasons.OVERWORLD_FALL) { | ||
return true; | ||
} | ||
|
||
world.setBlockMetadataWithNotify(blockX, blockY, blockZ, 16 | meta); | ||
if (entityplayer.getGamemode().consumeBlocks()) { | ||
--itemstack.stackSize; | ||
} | ||
} | ||
|
||
return true; | ||
} else { | ||
return false; | ||
} | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
src/main/java/mizurin/shieldmod/blocks/BlockModelAppleLeavesBloom.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package mizurin.shieldmod.blocks; | ||
|
||
import net.minecraft.client.render.block.model.BlockModelLeaves; | ||
import net.minecraft.client.render.stitcher.IconCoordinate; | ||
import net.minecraft.client.render.stitcher.TextureRegistry; | ||
import net.minecraft.client.render.tessellator.Tessellator; | ||
import net.minecraft.core.block.Block; | ||
import org.jetbrains.annotations.Nullable; | ||
import org.lwjgl.opengl.GL11; | ||
|
||
public class BlockModelAppleLeavesBloom<T extends Block> extends BlockModelLeaves<T> { | ||
private final IconCoordinate grownAppleOverlay = TextureRegistry.getTexture("shieldmod:block/leaves_apple_overlay"); | ||
private final IconCoordinate floweringAppleOverlay = TextureRegistry.getTexture("shieldmod:block/leaves_apple_flowering_overlay"); | ||
|
||
public BlockModelAppleLeavesBloom(Block block) { | ||
super(block, "shieldmod:block/leaves_apple"); | ||
} | ||
|
||
public boolean render(Tessellator tessellator, int x, int y, int z) { | ||
super.render(tessellator, x, y, z); | ||
int growthRate = (renderBlocks.blockAccess.getBlockMetadata(x, y, z) & 240) >> 4; | ||
if (growthRate > 0) { | ||
renderBlocks.overrideBlockTexture = this.grownAppleOverlay; | ||
} else { | ||
renderBlocks.overrideBlockTexture = this.floweringAppleOverlay; | ||
} | ||
|
||
this.renderStandardBlock(tessellator, this.block, x, y, z, 1.0F, 1.0F, 1.0F); | ||
renderBlocks.overrideBlockTexture = null; | ||
return true; | ||
} | ||
|
||
public void renderBlockOnInventory(Tessellator tessellator, int metadata, float brightness, float alpha, @Nullable Integer lightmapCoordinate) { | ||
super.renderBlockOnInventory(tessellator, metadata, brightness, alpha, lightmapCoordinate); | ||
GL11.glTranslatef(-0.5F, -0.5F, -0.5F); | ||
IconCoordinate appleCoord = this.grownAppleOverlay; | ||
GL11.glColor4f(brightness, brightness, brightness, alpha); | ||
tessellator.startDrawingQuads(); | ||
tessellator.setNormal(0.0F, -1.0F, 0.0F); | ||
this.renderBottomFace(tessellator, this.block, 0.0, 0.0, 0.0, appleCoord); | ||
tessellator.draw(); | ||
tessellator.startDrawingQuads(); | ||
tessellator.setNormal(0.0F, 1.0F, 0.0F); | ||
this.renderTopFace(tessellator, this.block, 0.0, 0.0, 0.0, appleCoord); | ||
tessellator.draw(); | ||
tessellator.startDrawingQuads(); | ||
tessellator.setNormal(0.0F, 0.0F, -1.0F); | ||
this.renderNorthFace(tessellator, this.block, 0.0, 0.0, 0.0, appleCoord); | ||
tessellator.draw(); | ||
tessellator.startDrawingQuads(); | ||
tessellator.setNormal(0.0F, 0.0F, 1.0F); | ||
this.renderSouthFace(tessellator, this.block, 0.0, 0.0, 0.0, appleCoord); | ||
tessellator.draw(); | ||
tessellator.startDrawingQuads(); | ||
tessellator.setNormal(-1.0F, 0.0F, 0.0F); | ||
this.renderWestFace(tessellator, this.block, 0.0, 0.0, 0.0, appleCoord); | ||
tessellator.draw(); | ||
tessellator.startDrawingQuads(); | ||
tessellator.setNormal(1.0F, 0.0F, 0.0F); | ||
this.renderEastFace(tessellator, this.block, 0.0, 0.0, 0.0, appleCoord); | ||
tessellator.draw(); | ||
GL11.glTranslatef(0.5F, 0.5F, 0.5F); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
src/main/java/mizurin/shieldmod/blocks/BlockSaplingApple.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package mizurin.shieldmod.blocks; | ||
|
||
import mizurin.shieldmod.WorldFeatureTreeApple; | ||
import net.minecraft.core.block.BlockSaplingBase; | ||
import net.minecraft.core.world.World; | ||
import net.minecraft.core.world.generate.feature.WorldFeature; | ||
import net.minecraft.core.world.generate.feature.tree.WorldFeatureTreeFancy; | ||
|
||
import java.util.Random; | ||
|
||
public class BlockSaplingApple extends BlockSaplingBase { | ||
public BlockSaplingApple(String key, int id) { | ||
super(key, id); | ||
} | ||
|
||
public void growTree(World world, int i, int j, int k, Random random) { | ||
WorldFeature treeBig = new WorldFeatureTreeFancy(RinBlocks.leavesApple.id, RinBlocks.logApple.id); | ||
WorldFeature treeSmall = new WorldFeatureTreeApple(RinBlocks.leavesApple.id, RinBlocks.logApple.id, 4); | ||
world.setBlock(i, j, k, 0); | ||
if (!((WorldFeature) treeSmall).generate(world, random, i, j, k) && !((WorldFeature) treeBig).generate(world, random, i, j, k)) { | ||
world.setBlock(i, j, k, this.id); | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package mizurin.shieldmod.blocks; | ||
|
||
import net.minecraft.client.render.block.color.BlockColor; | ||
import net.minecraft.client.render.block.color.BlockColorLeavesOak; | ||
import net.minecraft.client.render.block.model.BlockModelAxisAligned; | ||
import net.minecraft.client.render.block.model.BlockModelCrossedSquares; | ||
import net.minecraft.client.render.block.model.BlockModelLeaves; | ||
import net.minecraft.client.render.colorizer.Colorizer; | ||
import net.minecraft.core.block.Block; | ||
import net.minecraft.core.block.BlockLog; | ||
import net.minecraft.core.block.tag.BlockTags; | ||
import net.minecraft.core.item.block.ItemBlockLeaves; | ||
import net.minecraft.core.sound.BlockSound; | ||
import turniplabs.halplibe.helper.BlockBuilder; | ||
|
||
|
||
import java.util.function.Function; | ||
|
||
import static mizurin.shieldmod.ShieldMod.blockID; | ||
import static mizurin.shieldmod.item.Shields.MOD_ID; | ||
|
||
public class RinBlocks { | ||
|
||
public static Colorizer apple; | ||
public static Block logApple; | ||
public static Block leavesApple; | ||
public static Block leavesAppleFlowering; | ||
public static Block saplingApple; | ||
|
||
public void initializeBlockDetails() { | ||
|
||
} | ||
|
||
public void initializeBlocks() { | ||
BlockBuilder leaves = new BlockBuilder(MOD_ID) | ||
.setBlockSound(new BlockSound("step.grass", "step.grass", 1.0f, 1.0f)) | ||
.setHardness(0.2F) | ||
.setResistance(0.2F) | ||
.setFlammability(30, 60) | ||
.setTickOnLoad() | ||
.setVisualUpdateOnMetadata() | ||
.setItemBlock(ItemBlockLeaves::new) | ||
.setBlockColor(b -> new BlockColorLeavesOak(apple)) | ||
.setTags(BlockTags.MINEABLE_BY_AXE, BlockTags.MINEABLE_BY_HOE, BlockTags.MINEABLE_BY_SWORD, BlockTags.MINEABLE_BY_SHEARS, BlockTags.SHEARS_DO_SILK_TOUCH); | ||
|
||
|
||
BlockBuilder sapling = new BlockBuilder(MOD_ID) | ||
.setBlockSound(new BlockSound("step.grass", "step.grass", 1.0f, 1.0f)) | ||
.setHardness(0.0f) | ||
.setResistance(0.0f) | ||
.setBlockModel(BlockModelCrossedSquares::new) | ||
.setTags(BlockTags.BROKEN_BY_FLUIDS, BlockTags.PLANTABLE_IN_JAR); | ||
|
||
BlockBuilder log = new BlockBuilder(MOD_ID) | ||
.setBlockSound(new BlockSound("step.wood", "step.wood", 1.0f, 1.0f)) | ||
.setHardness(2.0F) | ||
.setResistance(1.0f) | ||
.setFlammability(5, 5) | ||
.setBlockModel(BlockModelAxisAligned::new) | ||
.setTags(BlockTags.MINEABLE_BY_AXE, BlockTags.FENCES_CONNECT); | ||
|
||
logApple = log | ||
.setBlockModel(block -> new BlockModelAxisAligned<>(block).withTextures("shieldmod:block/log_apple_top_test", "shieldmod:block/log_apple_side_test")) | ||
.build(new BlockLog("log.apple", ++blockID)); | ||
leavesApple = leaves | ||
.setBlockModel(block -> new BlockModelLeaves<>(block, "shieldmod:block/leaves_apple")) | ||
.build(new BlockLeavesApple("leaves.apple", ++blockID)); | ||
leavesAppleFlowering = leaves | ||
.setBlockModel(BlockModelAppleLeavesBloom::new) | ||
.build(new BlockLeavesAppleFlowering("leaves.apple.flowering", ++blockID)); | ||
saplingApple = sapling | ||
.setBlockModel(block -> new BlockModelCrossedSquares<>(block).withTextures("shieldmod:block/sapling_apple")) | ||
.build(new BlockSaplingApple("sapling.apple", ++blockID)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.