Skip to content

Commit 42baf50

Browse files
committed
feat: electrotine ore block particles
1 parent b9f5c52 commit 42baf50

File tree

3 files changed

+125
-6
lines changed

3 files changed

+125
-6
lines changed
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
package mrtjp.projectred.exploration.block;
2+
3+
import net.minecraft.block.AbstractBlock;
4+
import net.minecraft.block.Block;
5+
import net.minecraft.block.BlockState;
6+
import net.minecraft.block.SoundType;
7+
import net.minecraft.block.material.Material;
8+
import net.minecraft.entity.Entity;
9+
import net.minecraft.entity.player.PlayerEntity;
10+
import net.minecraft.item.BlockItem;
11+
import net.minecraft.item.BlockItemUseContext;
12+
import net.minecraft.item.ItemStack;
13+
import net.minecraft.particles.RedstoneParticleData;
14+
import net.minecraft.state.BooleanProperty;
15+
import net.minecraft.state.StateContainer;
16+
import net.minecraft.state.properties.BlockStateProperties;
17+
import net.minecraft.util.ActionResultType;
18+
import net.minecraft.util.Direction;
19+
import net.minecraft.util.Hand;
20+
import net.minecraft.util.math.BlockPos;
21+
import net.minecraft.util.math.BlockRayTraceResult;
22+
import net.minecraft.world.World;
23+
import net.minecraft.world.server.ServerWorld;
24+
import net.minecraftforge.common.ToolType;
25+
26+
import java.util.Random;
27+
28+
/**
29+
* All methods lifted straight from RedstoneOreBlock
30+
*/
31+
public class ElectrotineOreBlock extends OreBlock {
32+
33+
public static final BooleanProperty LIT = BlockStateProperties.LIT;
34+
35+
public static final RedstoneParticleData ELECTROTINE_PARTICLE = new RedstoneParticleData(
36+
15 / 255F, 103 / 255F, 178 / 255F, 0.6F);
37+
38+
public ElectrotineOreBlock(int harvestLevel, int minExp, int maxExp) {
39+
super(AbstractBlock.Properties.of(Material.STONE)
40+
.strength(3.0F, 3.0F)
41+
.harvestLevel(harvestLevel)
42+
.requiresCorrectToolForDrops()
43+
.harvestTool(ToolType.PICKAXE)
44+
.sound(SoundType.STONE)
45+
.lightLevel(s -> s.getValue(LIT) ? 9 : 0), harvestLevel, minExp, maxExp);
46+
47+
registerDefaultState(defaultBlockState().setValue(LIT, false));
48+
}
49+
50+
public void attack(BlockState state, World world, BlockPos pos, PlayerEntity player) {
51+
interact(state, world, pos);
52+
super.attack(state, world, pos, player);
53+
}
54+
55+
public void stepOn(World world, BlockPos pos, Entity player) {
56+
interact(world.getBlockState(pos), world, pos);
57+
super.stepOn(world, pos, player);
58+
}
59+
60+
public ActionResultType use(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockRayTraceResult rayTraceResult) {
61+
if (world.isClientSide) {
62+
spawnParticles(world, pos);
63+
} else {
64+
interact(state, world, pos);
65+
}
66+
67+
ItemStack itemstack = player.getItemInHand(hand);
68+
return itemstack.getItem() instanceof BlockItem && (new BlockItemUseContext(player, hand, itemstack, rayTraceResult)).canPlace() ? ActionResultType.PASS : ActionResultType.SUCCESS;
69+
}
70+
71+
private static void interact(BlockState state, World world, BlockPos pos) {
72+
spawnParticles(world, pos);
73+
if (!state.getValue(LIT)) {
74+
world.setBlock(pos, state.setValue(LIT, true), 3);
75+
}
76+
}
77+
78+
public boolean isRandomlyTicking(BlockState state) {
79+
return state.getValue(LIT);
80+
}
81+
82+
public void randomTick(BlockState state, ServerWorld world, BlockPos pos, Random random) {
83+
if (state.getValue(LIT)) {
84+
world.setBlock(pos, state.setValue(LIT, false), 3);
85+
}
86+
}
87+
88+
@Override
89+
public void animateTick(BlockState state, World world, BlockPos pos, Random random) {
90+
if (state.getValue(LIT)) {
91+
spawnParticles(world, pos);
92+
}
93+
}
94+
95+
private static void spawnParticles(World world, BlockPos pos) {
96+
double d0 = 0.5625D;
97+
Random random = world.random;
98+
99+
for (Direction direction : Direction.values()) {
100+
BlockPos blockpos = pos.relative(direction);
101+
if (!world.getBlockState(blockpos).isSolidRender(world, blockpos)) {
102+
Direction.Axis axis = direction.getAxis();
103+
double d1 = axis == Direction.Axis.X ? 0.5D + d0 * (double) direction.getStepX() : (double) random.nextFloat();
104+
double d2 = axis == Direction.Axis.Y ? 0.5D + d0 * (double) direction.getStepY() : (double) random.nextFloat();
105+
double d3 = axis == Direction.Axis.Z ? 0.5D + d0 * (double) direction.getStepZ() : (double) random.nextFloat();
106+
world.addParticle(ELECTROTINE_PARTICLE, (double) pos.getX() + d1, (double) pos.getY() + d2, (double) pos.getZ() + d3, 0.0D, 0.0D, 0.0D);
107+
}
108+
}
109+
}
110+
111+
protected void createBlockStateDefinition(StateContainer.Builder<Block, BlockState> stateBuilder) {
112+
stateBuilder.add(LIT);
113+
}
114+
}

src/exploration/java/mrtjp/projectred/exploration/block/OreBlock.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,19 @@ public class OreBlock extends Block {
1818
private final int minExp;
1919
private final int maxExp;
2020

21+
public OreBlock(AbstractBlock.Properties properties, int harvestLevel, int minExp, int maxExp) {
22+
super(properties);
23+
this.minExp = minExp;
24+
this.maxExp = maxExp;
25+
}
26+
2127
public OreBlock(int harvestLevel, int minExp, int maxExp) {
22-
super(AbstractBlock.Properties.of(Material.STONE)
23-
.strength(4.0F, 5.0F)
28+
this(AbstractBlock.Properties.of(Material.STONE)
29+
.strength(3.0F, 3.0F)
2430
.harvestLevel(harvestLevel)
2531
.requiresCorrectToolForDrops()
2632
.harvestTool(ToolType.PICKAXE)
27-
.sound(SoundType.STONE));
28-
this.minExp = minExp;
29-
this.maxExp = maxExp;
33+
.sound(SoundType.STONE), harvestLevel, minExp, maxExp);
3034
}
3135

3236
@Override

src/exploration/java/mrtjp/projectred/exploration/init/ExplorationBlocks.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package mrtjp.projectred.exploration.init;
22

3+
import mrtjp.projectred.exploration.block.ElectrotineOreBlock;
34
import mrtjp.projectred.exploration.block.OreBlock;
45
import net.minecraft.block.AbstractBlock;
56
import net.minecraft.block.Block;
@@ -62,7 +63,7 @@ public static void register() {
6263
BLOCKS.register(ID_COPPER_ORE, () -> new OreBlock(1, 0, 0));
6364
BLOCKS.register(ID_TIN_ORE, () -> new OreBlock(1, 0, 0));
6465
BLOCKS.register(ID_SILVER_ORE, () -> new OreBlock(2, 0, 0));
65-
BLOCKS.register(ID_ELECTROTINE_ORE, () -> new OreBlock(2, 1, 5));
66+
BLOCKS.register(ID_ELECTROTINE_ORE, () -> new ElectrotineOreBlock(2, 1, 5));
6667

6768
// Decorative blocks
6869
RegistryObject<Block> marbleBlock = BLOCKS.register(ID_MARBLE, () -> createDecorativeStoneBlock(2, 1F, 14F));

0 commit comments

Comments
 (0)