improve bullet physics

This commit is contained in:
Sen 2025-06-16 10:31:48 +02:00
parent fcc5e9b640
commit d566db0fc5
Signed by: sen
GPG key ID: 3AC50A6F47D1B722
7 changed files with 38 additions and 4 deletions

View file

@ -1008,4 +1008,8 @@ public class Block {
public void onDestroyedByFire(World world, BlockPos pos, State state) {
}
public boolean onShot(World world, BlockPos pos, State state, Entity projectile) {
return this.material.blocksMovement();
}
}

View file

@ -2,6 +2,7 @@ package common.block.artificial;
import common.block.Block;
import common.block.Material;
import common.entity.Entity;
import common.item.CheatTab;
import common.model.BlockLayer;
import common.rng.Random;
@ -9,6 +10,7 @@ import common.util.BlockPos;
import common.util.Facing;
import common.world.IWorldAccess;
import common.world.State;
import common.world.World;
public class BlockGlass extends Block {
public BlockGlass() {
@ -41,4 +43,9 @@ public class BlockGlass extends Block {
Block block = state.getBlock();
return world.getState(pos.offset(side.getOpposite())) != state || (block != this && super.shouldSideBeRendered(world, pos, side));
}
public boolean onShot(World world, BlockPos pos, State state, Entity projectile) {
world.destroyBlock(pos, true);
return false;
}
}

View file

@ -210,6 +210,12 @@ public class BlockPane extends Block
return this.material == Material.SOLID;
}
public boolean onShot(World world, BlockPos pos, State state, Entity projectile) {
if(this.material != Material.SOLID)
world.destroyBlock(pos, true);
return this.material == Material.SOLID;
}
protected String getPaneBase(State state) {
return "glass";
}

View file

@ -2,6 +2,7 @@ package common.block.artificial;
import common.block.BlockDirectional;
import common.block.Material;
import common.entity.Entity;
import common.entity.types.EntityLiving;
import common.init.Items;
import common.item.Item;
@ -66,4 +67,9 @@ public class BlockSkull extends BlockDirectional {
public boolean isXrayVisible() {
return true;
}
public boolean onShot(World world, BlockPos pos, State state, Entity projectile) {
world.destroyBlock(pos, true);
return true;
}
}

View file

@ -2,12 +2,15 @@ package common.block.natural;
import common.block.Block;
import common.block.Material;
import common.entity.Entity;
import common.init.Items;
import common.item.CheatTab;
import common.item.Item;
import common.rng.Random;
import common.util.BlockPos;
import common.util.ExtMath;
import common.world.State;
import common.world.World;
public class BlockGlowstone extends Block
{
@ -41,6 +44,11 @@ public class BlockGlowstone extends Block
return Items.glowstone_dust;
}
public boolean onShot(World world, BlockPos pos, State state, Entity projectile) {
world.destroyBlock(pos, true);
return false;
}
// /**
// * Get the MapColor for this Block and the given BlockState
// */

View file

@ -16,6 +16,7 @@ import common.util.ExtMath;
import common.util.HitPosition;
import common.util.Vec3;
import common.vars.Vars;
import common.world.State;
import common.world.World;
public class EntityBullet extends Entity implements IProjectile, IObjectData
@ -286,11 +287,13 @@ public class EntityBullet extends Entity implements IProjectile, IObjectData
}
else
{
State state = movingobjectposition.block != null ? this.worldObj.getState(movingobjectposition.block) : null;
if(state == null || state.getBlock().onShot(this.worldObj, movingobjectposition.block, state, this)) {
this.playSound(SoundEvent.METALHIT, 0.5F);
this.setDead();
}
}
}
this.posX += this.motionX;
this.posY += this.motionY;

View file

@ -519,7 +519,7 @@ public abstract class ItemRegistry {
registerItem("poisonous_potato", (new ItemFood(2, false)).setPotionEffect(Potion.POISON, 5, 0, 0.6F).setDisplay("Giftige Kartoffel").setMaxStackSize(128));
registerItem("golden_carrot", (new ItemFood(6, false)).setDisplay("Goldene Karotte")
.setPotionEffect(PotionHelper.goldenCarrotEffect).setTab(CheatTab.MISC));
registerItem((new ItemSmallBlock(Blocks.skull)).setDisplay("Schädel"));
registerItem((new ItemSmallBlock(Blocks.skull)).setDisplay("Schädel").setTab(CheatTab.DECORATION));
registerItem("carrot_on_a_stick", (new ItemCarrotOnAStick()).setDisplay("Karottenrute"));
registerItem("charge_crystal", (new ItemEffect()).setDisplay("Energiekristall").setTab(CheatTab.MISC).setColor(TextColor.DMAGENTA));
registerItem("pumpkin_pie", (new ItemFood(8, false)).setDisplay("Kürbiskuchen").setTab(CheatTab.MISC));