Compare commits

..

No commits in common. "c735b06779308ddfba212a4d308f982f454a2f3c" and "9bf8b8f5d91cbf5d0df00af6a751a6446e8328b0" have entirely different histories.

2 changed files with 81 additions and 113 deletions

View File

@ -1,21 +1,15 @@
package me.parsell.wireddust.common; package me.parsell.wireddust.common;
import java.util.Iterator;
import java.util.Random; import java.util.Random;
import net.fabricmc.api.EnvType; import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment; import net.fabricmc.api.Environment;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.CampfireBlock;
import net.minecraft.block.TntBlock;
import net.minecraft.entity.EquipmentSlot;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Items; import net.minecraft.item.Items;
import net.minecraft.particle.ParticleTypes; import net.minecraft.particle.ParticleTypes;
import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.state.StateManager; import net.minecraft.state.StateManager;
import net.minecraft.state.property.BooleanProperty; import net.minecraft.state.property.BooleanProperty;
import net.minecraft.state.property.Properties; import net.minecraft.state.property.Properties;
@ -23,127 +17,104 @@ import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand; import net.minecraft.util.Hand;
import net.minecraft.util.hit.BlockHitResult; import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction; import net.minecraft.util.math.Box;
import net.minecraft.util.math.Direction.Axis; import net.minecraft.util.math.Direction.Axis;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraft.world.WorldAccess;
// TODO: All the magic to make this work the way i want // TODO: All the magic to make this work the way i want
public class WDGunpowderWireBlock extends WDWireBlock{ public class WDGunpowderWireBlock extends WDWireBlock{
public static final BooleanProperty LIT; public static final BooleanProperty LIT;
public static final BooleanProperty BURNT;
public WDGunpowderWireBlock(Settings settings) { public WDGunpowderWireBlock(Settings settings) {
super(settings); super(settings);
this.setDefaultState((BlockState)((BlockState)((BlockState)((BlockState)((BlockState)((BlockState)this.stateManager.getDefaultState()).with(WIRE_CONNECTION_NORTH, WDWireConnection.NONE)).with(WIRE_CONNECTION_EAST, WDWireConnection.NONE)).with(WIRE_CONNECTION_SOUTH, WDWireConnection.NONE)).with(WIRE_CONNECTION_WEST, WDWireConnection.NONE)).with(LIT, false).with(BURNT, false)); this.setDefaultState((BlockState)((BlockState)((BlockState)((BlockState)((BlockState)((BlockState)this.stateManager.getDefaultState()).with(WIRE_CONNECTION_NORTH, WDWireConnection.NONE)).with(WIRE_CONNECTION_EAST, WDWireConnection.NONE)).with(WIRE_CONNECTION_SOUTH, WDWireConnection.NONE)).with(WIRE_CONNECTION_WEST, WDWireConnection.NONE)).with(LIT, false));
} }
@Override @Override
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) { protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
super.appendProperties(builder.add(LIT, BURNT)); super.appendProperties(builder.add(LIT));
} }
private boolean hasUpConnection(BlockState state){ private boolean hasUpConnection(BlockState state){
return ((WDWireConnection)state.get(WIRE_CONNECTION_NORTH)).isConnectedUp() || return ((WDWireConnection)state.get(WIRE_CONNECTION_NORTH)).isConnectedUp() ||
((WDWireConnection)state.get(WIRE_CONNECTION_SOUTH)).isConnectedUp() || ((WDWireConnection)state.get(WIRE_CONNECTION_SOUTH)).isConnectedUp() ||
((WDWireConnection)state.get(WIRE_CONNECTION_EAST)).isConnectedUp() || ((WDWireConnection)state.get(WIRE_CONNECTION_EAST)).isConnectedUp() ||
((WDWireConnection)state.get(WIRE_CONNECTION_WEST)).isConnectedUp(); ((WDWireConnection)state.get(WIRE_CONNECTION_WEST)).isConnectedUp();
} }
@Environment(EnvType.CLIENT) static boolean pp = true;
public void randomDisplayTick(BlockState state, World world, BlockPos pos, Random random) {
if (state.get(LIT)){
// get random double, within bounds x/y_min and x/y_max
double x_min = super.STATE_TO_VOXELSHAPE.get(state).getMin(Axis.X);
double z_min = super.STATE_TO_VOXELSHAPE.get(state).getMin(Axis.Z);
double x_max = super.STATE_TO_VOXELSHAPE.get(state).getMax(Axis.X);
double z_max = super.STATE_TO_VOXELSHAPE.get(state).getMax(Axis.Z);
double x_rand = x_min + (x_max - x_min) * random.nextDouble();
double z_rand = z_min + (z_max - z_min) * random.nextDouble();
double y_rand = 0.1d; // TODO: Supprt UP state
@Environment(EnvType.CLIENT)
public void randomDisplayTick(BlockState state, World world, BlockPos pos, Random random) {
if (state.get(LIT)){
// get random double, within bounds x/y_min and x/y_max
double x_min = super.STATE_TO_VOXELSHAPE.get(state).getMin(Axis.X);
double z_min = super.STATE_TO_VOXELSHAPE.get(state).getMin(Axis.Z);
double x_max = super.STATE_TO_VOXELSHAPE.get(state).getMax(Axis.X);
double z_max = super.STATE_TO_VOXELSHAPE.get(state).getMax(Axis.Z);
double x_rand = x_min + (x_max - x_min) * random.nextDouble();
double z_rand = z_min + (z_max - z_min) * random.nextDouble();
if (hasUpConnection(state)){ double y_rand = 0.1d;
if (z_rand < 0.1d && state.get(WIRE_CONNECTION_NORTH).isConnectedUp() ||
z_rand > 0.9d && state.get(WIRE_CONNECTION_SOUTH).isConnectedUp() ||
x_rand < 0.1d && state.get(WIRE_CONNECTION_WEST).isConnectedUp() ||
x_rand > 0.9d && state.get(WIRE_CONNECTION_EAST).isConnectedUp()) {
y_rand = 0.1D + (0.9D - 0.1D) * random.nextDouble();
}
}
world.addParticle(ParticleTypes.FLAME, pos.getX() + x_rand, pos.getY() + y_rand, pos.getZ() + z_rand, 0.0, 0.0, 0.0); if (hasUpConnection(state)){
super.randomDisplayTick(state, world, pos, random); if (z_rand < 0.1d && state.get(WIRE_CONNECTION_NORTH).isConnectedUp() ||
} z_rand > 0.9d && state.get(WIRE_CONNECTION_SOUTH).isConnectedUp() ||
} x_rand < 0.1d && state.get(WIRE_CONNECTION_WEST).isConnectedUp() ||
x_rand > 0.9d && state.get(WIRE_CONNECTION_EAST).isConnectedUp()) {
y_rand = 0.1D + (0.9D - 0.1D) * random.nextDouble();
}
}
// TODO: TEST KILLING MINECRAFT WITH REDSTONE & FILL COMMANDS System.out.printf("X: %1.2f | Y: %1.2f | Z: %1.2f\n", x_rand, y_rand, z_rand);
@Override
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit){
if(world.isClient)
if(player.getStackInHand(hand).getItem().equals(Items.FLINT_AND_STEEL) || !player.hasStackEquipped(EquipmentSlot.MAINHAND))
return ActionResult.SUCCESS;
else
return ActionResult.PASS;
if(player.abilities.allowModifyWorld){
if(!state.get(LIT) && player.getStackInHand(hand).getItem().equals(Items.FLINT_AND_STEEL)){
player.getStackInHand(hand).damage(1, world.getRandom(), (ServerPlayerEntity)player);
light(world, pos, state);
return ActionResult.SUCCESS;
}
}
super.onUse(state, world, pos, player, hand, hit); //NEW
return ActionResult.PASS; /*
} double rand_x, rand_y, rand_z;
boolean validParticle = false;
public void light(World world, BlockPos pos, BlockState state){ if (pp) {
world.setBlockState(pos, state.with(LIT, true)); pp = false;
scheduleTick(world, pos); System.out.println(super.STATE_TO_VOXELSHAPE.get(state).getBoundingBoxes().size());
} }
public void scheduleTick(WorldAccess world, BlockPos pos) { do{
if (!world.isClient() && !world.getBlockTickScheduler().isScheduled(pos, this)) { rand_x = random.nextDouble();
world.getBlockTickScheduler().schedule(pos, this, 60); rand_y = random.nextDouble();
} rand_z = random.nextDouble();
}
// Three things need to happen' for (Box b : super.STATE_TO_VOXELSHAPE.get(state).getBoundingBoxes()){
// 1. Set neighbors to lit, if self and schedule another tick update if (b.contains(rand_x, rand_y, rand_z))
// 2. start fire on "flammable" blocks and schedule another tick update | half validParticle = true;
// 3. Destroy self break;
@Override }
public void scheduledTick(BlockState state, ServerWorld world, BlockPos pos, Random random) { }while (!validParticle); */
if(!state.get(BURNT)) {
Iterator<Direction> dirItr = Direction.Type.HORIZONTAL.iterator();
while(dirItr.hasNext()) {
Direction dir = dirItr.next();
BlockPos offsetPos = pos.offset(dir);
BlockState offsetBlockState = world.getBlockState(offsetPos);
if(state.get(super.DIRECTION_TO_WIRE_CONNECTION.get(dir)).isConnected())
if(offsetBlockState.isOf(this))
light(world, offsetPos, offsetBlockState);
else if(offsetBlockState.isOf(Blocks.TNT)) {
TntBlock.primeTnt(world, offsetPos);
world.setBlockState(offsetPos, Blocks.AIR.getDefaultState());
} else if(offsetBlockState.isOf(Blocks.CAMPFIRE) && !offsetBlockState.get(CampfireBlock.LIT))
world.setBlockState(offsetPos, offsetBlockState.with(CampfireBlock.LIT, true));
else if(false) // TODO: make flammable blocks array
;
}
world.setBlockState(pos, state.with(BURNT, true)); world.addParticle(ParticleTypes.FLAME, pos.getX() + x_rand, pos.getY() + y_rand, pos.getZ() + z_rand, 0.0, 0.0, 0.0);
scheduleTick(world, pos); super.randomDisplayTick(state, world, pos, random);
} else { }
world.setBlockState(pos, Blocks.AIR.getDefaultState()); }
}
} // TODO: TEST KILLING MINECRAFT WITH REDSTONE & FILL COMMANDS
@Override
static { public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit){
LIT = Properties.LIT; if(world.isClient)
BURNT = BooleanProperty.of("burnt"); return ActionResult.SUCCESS;
} if(player.abilities.allowModifyWorld){
if(!state.get(LIT) && player.getStackInHand(hand).getItem().equals(Items.FLINT_AND_STEEL)){
player.getStackInHand(hand).damage(1, world.getRandom(), (ServerPlayerEntity)player);
world.setBlockState(pos, state.with(LIT, true));
return ActionResult.SUCCESS;
}
}
super.onUse(state, world, pos, player, hand, hit);
return ActionResult.PASS;
}
static {
LIT = Properties.LIT;
}
} }

View File

@ -215,10 +215,7 @@ public class WDWireBlock extends Block{
@Override // For each link, set to break and update the blocks around me (above and below) @Override // For each link, set to break and update the blocks around me (above and below)
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit){ public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit){
if(world.isClient) if(world.isClient)
if(hasConnection(state) && !player.hasStackEquipped(EquipmentSlot.MAINHAND)) return ActionResult.SUCCESS;
return ActionResult.SUCCESS;
else
return ActionResult.PASS;
if(player.abilities.allowModifyWorld) if(player.abilities.allowModifyWorld)
if(hasConnection(state) && !player.hasStackEquipped(EquipmentSlot.MAINHAND)) { if(hasConnection(state) && !player.hasStackEquipped(EquipmentSlot.MAINHAND)) {
Iterator<Direction> dirItr = Direction.Type.HORIZONTAL.iterator(); Iterator<Direction> dirItr = Direction.Type.HORIZONTAL.iterator();