fix block hardness + sounds
This commit is contained in:
parent
9f9a2e9399
commit
2504f24b7b
20 changed files with 70 additions and 54 deletions
|
@ -901,7 +901,7 @@ public abstract class GuiContainer extends Gui
|
|||
for(Iterator<ItemStack> iter = ITEM_LIST.iterator(); iter.hasNext();) {
|
||||
ItemStack stack = iter.next();
|
||||
for(String line : this.getTooltip(stack)) {
|
||||
if(line.toLowerCase().contains(this.cheatLast.toLowerCase())) {
|
||||
if(Color.stripCodes(line).toLowerCase().contains(this.cheatLast.toLowerCase())) {
|
||||
stack = null;
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -1491,6 +1491,12 @@ public class ClientPlayer implements IClientPlayer
|
|||
this.gm.effectRenderer.destroyBlock(blockPosIn, state);
|
||||
break;
|
||||
|
||||
case 2003:
|
||||
State state1 = BlockRegistry.byId(data);
|
||||
if(state1 != null)
|
||||
this.gm.effectRenderer.destroyBlock(blockPosIn, state1);
|
||||
break;
|
||||
|
||||
case 2002:
|
||||
double d13 = (double)blockPosIn.getX();
|
||||
double d14 = (double)blockPosIn.getY();
|
||||
|
|
|
@ -8,14 +8,12 @@ import common.entity.npc.EntityNPC;
|
|||
import common.init.BlockRegistry;
|
||||
import common.init.Blocks;
|
||||
import common.init.EntityRegistry;
|
||||
import common.init.SoundEvent;
|
||||
import common.item.ItemControl;
|
||||
import common.item.ItemStack;
|
||||
import common.packet.CPacketAction;
|
||||
import common.packet.CPacketBreak;
|
||||
import common.packet.CPacketClick;
|
||||
import common.packet.CPacketPlace;
|
||||
import common.sound.PositionedSound;
|
||||
import common.util.LocalPos;
|
||||
import common.util.Facing;
|
||||
import common.util.Vec3;
|
||||
|
@ -29,7 +27,6 @@ public class PlayerController {
|
|||
private LocalPos position = new LocalPos(-1, -World.MAX_SIZE_Y - 1, -1);
|
||||
private ItemStack stack;
|
||||
private float damage;
|
||||
private float stepCounter;
|
||||
private int delay;
|
||||
private boolean hitting;
|
||||
private int lastSelected;
|
||||
|
@ -109,7 +106,6 @@ public class PlayerController {
|
|||
this.position = pos;
|
||||
this.stack = this.gm.player.getHeldItem();
|
||||
this.damage = 0.0F;
|
||||
this.stepCounter = 0.0F;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -148,19 +144,11 @@ public class PlayerController {
|
|||
else {
|
||||
this.damage += block.getHardness(this.gm.player, this.gm.player.worldObj, pos);
|
||||
|
||||
if(this.stepCounter % 4.0F == 0.0F) {
|
||||
this.gm.getSoundManager().playSound(new PositionedSound(SoundEvent.BLOCK_DAMAGE, 0.05F,
|
||||
(float)pos.getX() + 0.5F, (float)pos.getY() + 0.5F, (float)pos.getZ() + 0.5F));
|
||||
}
|
||||
|
||||
++this.stepCounter;
|
||||
|
||||
if(this.damage >= 1.0F) {
|
||||
this.hitting = false;
|
||||
this.handler.addToSendQueue(new CPacketBreak(CPacketBreak.Action.STOP_DESTROY_BLOCK, pos, face));
|
||||
this.destroyBlock(pos, face);
|
||||
this.damage = 0.0F;
|
||||
this.stepCounter = 0.0F;
|
||||
this.delay = 5;
|
||||
}
|
||||
return true;
|
||||
|
|
Binary file not shown.
Binary file not shown.
|
@ -102,7 +102,7 @@ public class EntityAIEatGrass extends EntityAIBase
|
|||
{
|
||||
if (Vars.mobGrief)
|
||||
{
|
||||
this.entityWorld.playEffect(2001, blockpos1, BlockRegistry.getId(Blocks.grass.getState()));
|
||||
this.entityWorld.playEffect(2003, blockpos1, BlockRegistry.getId(Blocks.grass.getState()));
|
||||
this.entityWorld.setState(blockpos1, Blocks.dirt.getState(), 2);
|
||||
}
|
||||
|
||||
|
|
|
@ -35,6 +35,7 @@ import common.item.CheatTab;
|
|||
import common.item.Item;
|
||||
import common.item.ItemStack;
|
||||
import common.item.ItemWeight;
|
||||
import common.log.Log;
|
||||
import common.model.Model;
|
||||
import common.model.Model.ModelProvider;
|
||||
import common.model.GuiPosition;
|
||||
|
@ -179,7 +180,7 @@ public class Block {
|
|||
private int miningLevel;
|
||||
private int encouragement;
|
||||
private int flammability;
|
||||
private float hardness;
|
||||
private int hardness;
|
||||
private float radiation;
|
||||
private float slipperiness;
|
||||
protected double minX;
|
||||
|
@ -371,6 +372,19 @@ public class Block {
|
|||
this.setDefaultState(this.getBaseState());
|
||||
this.savedProps = getPropertyList(this.getProperties(), this.getUnsavedProperties());
|
||||
this.saved = getStateList(this.savedProps, this.states);
|
||||
this.computeHardness();
|
||||
}
|
||||
|
||||
private void computeHardness() {
|
||||
if(this.miningTool != null) {
|
||||
if(this.miningTool.isLevelled())
|
||||
this.hardness = (this.miningLevel + 1) * 5;
|
||||
else
|
||||
this.hardness = 2;
|
||||
}
|
||||
else {
|
||||
this.hardness = 0;
|
||||
}
|
||||
}
|
||||
|
||||
public final Block setOpacity(int opacity) {
|
||||
|
@ -385,7 +399,6 @@ public class Block {
|
|||
}
|
||||
|
||||
public final Block setHardness(float hardness) {
|
||||
this.hardness = hardness;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -417,6 +430,7 @@ public class Block {
|
|||
throw new IllegalArgumentException("Abbauwerkzeug " + tool + " muss Levels besitzen");
|
||||
this.miningTool = tool;
|
||||
this.miningLevel = level;
|
||||
this.computeHardness();
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -427,6 +441,7 @@ public class Block {
|
|||
throw new IllegalArgumentException("Abbauwerkzeug " + tool + " darf keine Levels besitzen");
|
||||
this.miningTool = tool;
|
||||
this.miningLevel = -1;
|
||||
this.computeHardness();
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -513,7 +528,7 @@ public class Block {
|
|||
return this.material.isOpaque() && this.isFullCube();
|
||||
}
|
||||
|
||||
public final float getRawHardness() {
|
||||
public final int getHardness() {
|
||||
return this.hardness;
|
||||
}
|
||||
|
||||
|
@ -546,7 +561,7 @@ public class Block {
|
|||
}
|
||||
|
||||
public final float getHardness(EntityNPC player, World world, LocalPos pos) {
|
||||
float f = this.getHardness(world, pos);
|
||||
float f = (float)this.hardness;
|
||||
return f < 0.0F ? 0.0F
|
||||
: (!player.canHarvestBlock(this) ? player.getToolDigEfficiency(this) / f / 100.0F
|
||||
: player.getToolDigEfficiency(this) / f / 30.0F);
|
||||
|
@ -629,10 +644,6 @@ public class Block {
|
|||
return false;
|
||||
}
|
||||
|
||||
public float getHardness(World world, LocalPos pos) {
|
||||
return this.hardness;
|
||||
}
|
||||
|
||||
public void getCollisionBoxes(World world, LocalPos pos, State state, BoundingBox mask, List<BoundingBox> list, Entity colliding) {
|
||||
BoundingBox bb = this.getCollisionBox(world, pos, state);
|
||||
if(bb != null && mask.intersectsWith(bb))
|
||||
|
@ -1072,6 +1083,8 @@ public class Block {
|
|||
public void getTooltips(ItemStack stack, EntityNPC player, List<String> tooltip) {
|
||||
if(this.light != 0)
|
||||
tooltip.add(Color.BLUE + "Licht" + Color.DARK_GRAY + ": " + Color.NEON + String.format("%06x", this.light));
|
||||
if(this.hardness != 0)
|
||||
tooltip.add(Color.BLUE + "Härte" + Color.DARK_GRAY + ": " + Color.NEON + this.hardness);
|
||||
}
|
||||
|
||||
@Clientside
|
||||
|
|
|
@ -15,9 +15,6 @@ public enum Material {
|
|||
SOLID {{
|
||||
this.setRequiredTool(Equipment.PICKAXE);
|
||||
}},
|
||||
DIGGABLE {{ // can harvest with shovel
|
||||
this.setRequiredTool(Equipment.SHOVEL);
|
||||
}},
|
||||
TRANSLUCENT {{
|
||||
this.setTranslucent();
|
||||
}},
|
||||
|
@ -25,7 +22,7 @@ public enum Material {
|
|||
this.setBurning();
|
||||
}},
|
||||
SOFT {{ // can break faster with sword, can't connect to fences+walls
|
||||
this.setNoPushMobility().setTool(Equipment.AXE);
|
||||
this.setNoPushMobility();
|
||||
}},
|
||||
PISTON {{
|
||||
this.setImmovableMobility();
|
||||
|
@ -34,7 +31,7 @@ public enum Material {
|
|||
this.setRequiredTool(Equipment.PICKAXE).setImmovableMobility();
|
||||
}},
|
||||
PLANT {{ // can break faster with sword
|
||||
this.setNonSolid().setNoPushMobility().setTool(Equipment.AXE);
|
||||
this.setNonSolid().setNoPushMobility();
|
||||
}},
|
||||
SMALL {{ // can be placed more easily
|
||||
this.setNonSolid().setNoPushMobility();
|
||||
|
@ -64,16 +61,16 @@ public enum Material {
|
|||
this.setLiquid(true).setReplaceable().setNoPushMobility();
|
||||
}},
|
||||
LEAVES {{ // can break faster with sword, precipitation block, special treatment in some worldgen
|
||||
this.setBurning().setTranslucent().setNoPushMobility().setTool(Equipment.SHEARS);
|
||||
this.setBurning().setTranslucent().setNoPushMobility();
|
||||
}},
|
||||
BUSH {{ // can break faster with sword, can be replaced by small tree leaves
|
||||
this.setNonSolid().setBurning().setNoPushMobility().setReplaceable().setTool(Equipment.AXE);
|
||||
this.setNonSolid().setBurning().setNoPushMobility().setReplaceable();
|
||||
}},
|
||||
FIRE {{
|
||||
this.setNonSolid().setReplaceable().setNoPushMobility();
|
||||
}},
|
||||
POWDER {{ // can harvest with shovel, precipitation block
|
||||
this.setNonSolid().setReplaceable().setRequiredTool(Equipment.SHOVEL).setNoPushMobility();
|
||||
this.setNonSolid().setReplaceable().setNoPushMobility();
|
||||
}},
|
||||
FLUFF {{ // can harvest with shears
|
||||
this.setPassable().setRequiredTool(Equipment.SWORD).setNoPushMobility();
|
||||
|
|
|
@ -54,7 +54,7 @@ public class BlockSlab extends Block implements Directional {
|
|||
|
||||
this.setOpacity(255);
|
||||
this.base = base;
|
||||
this.setHardness(this.base.getRawHardness());
|
||||
this.setHardness(this.base.getHardness());
|
||||
this.textureTop = top;
|
||||
this.textureBottom = bottom;
|
||||
this.textureSide = side;
|
||||
|
|
|
@ -52,7 +52,7 @@ public class BlockStairs extends Block implements Rotatable
|
|||
super(base.getMaterial());
|
||||
this.setDefaultState(this.getBaseState().withProperty(FACING, Facing.NORTH).withProperty(HALF, BlockStairs.EnumHalf.BOTTOM).withProperty(SHAPE, BlockStairs.EnumShape.STRAIGHT));
|
||||
this.base = base;
|
||||
this.setHardness(this.base.getRawHardness());
|
||||
this.setHardness(this.base.getHardness());
|
||||
this.setOpacity(255);
|
||||
this.setTab(base.getTab());
|
||||
this.downTex = down;
|
||||
|
|
|
@ -42,7 +42,7 @@ public class BlockWall extends Block
|
|||
this.base = modelBlock;
|
||||
this.texture = texture;
|
||||
this.setDefaultState(this.getBaseState().withProperty(UP, Boolean.valueOf(false)).withProperty(NORTH, Boolean.valueOf(false)).withProperty(EAST, Boolean.valueOf(false)).withProperty(SOUTH, Boolean.valueOf(false)).withProperty(WEST, Boolean.valueOf(false)));
|
||||
this.setHardness(modelBlock.getRawHardness());
|
||||
this.setHardness(modelBlock.getHardness());
|
||||
this.setTab(modelBlock.getTab());
|
||||
WALLS.add(this);
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package common.block.natural;
|
|||
|
||||
import common.block.Block;
|
||||
import common.block.Material;
|
||||
import common.enchantment.EnchantmentHelper;
|
||||
import common.entity.npc.EntityNPC;
|
||||
import common.init.Blocks;
|
||||
import common.init.Items;
|
||||
|
@ -9,6 +10,7 @@ import common.init.SoundEvent;
|
|||
import common.item.CheatTab;
|
||||
import common.item.Item;
|
||||
import common.item.ItemStack;
|
||||
import common.item.tool.ItemTool;
|
||||
import common.model.Model;
|
||||
import common.model.Model.ModelProvider;
|
||||
import common.properties.Property;
|
||||
|
@ -17,6 +19,7 @@ import common.rng.Random;
|
|||
import common.tileentity.TileEntity;
|
||||
import common.util.LocalPos;
|
||||
import common.util.BoundingBox;
|
||||
import common.util.Equipment;
|
||||
import common.util.Facing;
|
||||
import common.vars.Vars;
|
||||
import common.world.IBlockAccess;
|
||||
|
@ -108,9 +111,10 @@ public class BlockSnow extends Block
|
|||
|
||||
public void postBroken(World worldIn, EntityNPC player, LocalPos pos, State state, TileEntity te)
|
||||
{
|
||||
if (!worldIn.client && player.getHeldItem() != null && player.getHeldItem().getItem() instanceof ItemTool tool && tool.getToolType() == Equipment.SHOVEL)
|
||||
dropItem(worldIn, pos, new ItemStack(Items.snowball, ((Integer)state.getValue(LAYERS)).intValue() + 1));
|
||||
worldIn.setBlockToAir(pos);
|
||||
// player.triggerAchievement(StatRegistry.mineBlockStatArray[BlockRegistry.getIdFromBlock(this)]);
|
||||
else
|
||||
super.postBroken(worldIn, player, pos, state, te);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -2,18 +2,25 @@ package common.block.natural;
|
|||
|
||||
import common.block.Block;
|
||||
import common.block.Material;
|
||||
import common.enchantment.EnchantmentHelper;
|
||||
import common.entity.npc.EntityNPC;
|
||||
import common.init.Items;
|
||||
import common.item.CheatTab;
|
||||
import common.item.Item;
|
||||
import common.item.ItemStack;
|
||||
import common.item.tool.ItemTool;
|
||||
import common.rng.Random;
|
||||
import common.tileentity.TileEntity;
|
||||
import common.util.Equipment;
|
||||
import common.util.LocalPos;
|
||||
import common.vars.Vars;
|
||||
import common.world.State;
|
||||
import common.world.World;
|
||||
import common.world.AWorldServer;
|
||||
|
||||
public class BlockSnowBlock extends Block {
|
||||
public BlockSnowBlock() {
|
||||
super(Material.DIGGABLE);
|
||||
super(Material.LOOSE);
|
||||
this.setTicked();
|
||||
this.setTab(CheatTab.NATURE);
|
||||
}
|
||||
|
@ -23,7 +30,14 @@ public class BlockSnowBlock extends Block {
|
|||
}
|
||||
|
||||
protected int getDropAmount(Random rand) {
|
||||
return rand.range(2, 4);
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void postBroken(World worldIn, EntityNPC player, LocalPos pos, State state, TileEntity te) {
|
||||
if(!worldIn.client && player.getHeldItem() != null && player.getHeldItem().getItem() instanceof ItemTool tool && tool.getToolType() == Equipment.SHOVEL && !EnchantmentHelper.getSilkTouchModifier(player))
|
||||
dropItem(worldIn, pos, new ItemStack(Items.snowball, worldIn.rand.range(2, 4)));
|
||||
else
|
||||
super.postBroken(worldIn, player, pos, state, te);
|
||||
}
|
||||
|
||||
public void tick(AWorldServer world, LocalPos pos, State state, Random rand) {
|
||||
|
|
|
@ -476,11 +476,6 @@ public class BlockPistonBase extends Block implements Directional
|
|||
{
|
||||
if (blockIn != Blocks.piston && blockIn != Blocks.sticky_piston)
|
||||
{
|
||||
if (blockIn.getHardness(worldIn, pos) == -1.0F)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (blockIn.getMobilityFlag() == 2)
|
||||
{
|
||||
return false;
|
||||
|
|
|
@ -317,7 +317,7 @@ public class EntityRabbit extends EntityAnimal {
|
|||
}
|
||||
|
||||
protected void consumeBlock(LocalPos pos, State state) {
|
||||
this.worldObj.playEffect(2001, pos, BlockRegistry.getId(state));
|
||||
this.worldObj.playEffect(2003, pos, BlockRegistry.getId(state));
|
||||
this.foodCooldown = this.rand.excl(10, this.isChild() ? 20 : 50);
|
||||
if(this.isChild())
|
||||
this.grow(this.rand.range(250, 350));
|
||||
|
|
|
@ -165,8 +165,8 @@ public abstract class BlockRegistry {
|
|||
register("gravel", (new BlockGravel()).setHardness(0.6F).setDisplay("Kies").setMiningTool(Equipment.SHOVEL));
|
||||
register("ash", (new BlockFalling(Material.LOOSE)).setHardness(0.2F).setDisplay("Asche")
|
||||
.setTab(CheatTab.NATURE).setMiningTool(Equipment.SHOVEL));
|
||||
register("snow_layer", (new BlockSnow()).setHardness(0.1F).setDisplay("Schnee").setOpacity(0).setMiningTool(Equipment.SHOVEL));
|
||||
register("snow", (new BlockSnowBlock()).setHardness(0.2F).setDisplay("Schnee").setMiningTool(Equipment.SHOVEL));
|
||||
register("snow_layer", (new BlockSnow()).setHardness(0.1F).setDisplay("Schnee").setOpacity(0));
|
||||
register("snow", (new BlockSnowBlock()).setHardness(0.2F).setDisplay("Schnee"));
|
||||
register("ice", (new BlockIce()).setHardness(0.5F).setOpacity(3).setDisplay("Eis").setMiningTool(Equipment.PICKAXE, 0));
|
||||
register("packed_ice", (new BlockPackedIce()).setHardness(0.5F).setDisplay("Packeis").setMiningTool(Equipment.PICKAXE, 0));
|
||||
register("soul_sand", (new BlockSoulSand()).setHardness(0.5F).setDisplay("Seelensand").setMiningTool(Equipment.SHOVEL));
|
||||
|
@ -242,7 +242,7 @@ public abstract class BlockRegistry {
|
|||
|
||||
|
||||
for(BlockTallGrass.EnumType type : BlockTallGrass.EnumType.values()) {
|
||||
register(type.getName(), (new BlockTallGrass(type)).setHardness(0.0F).setDisplay(type.getDisplay()).setMiningTool(Equipment.SHEARS));
|
||||
register(type.getName(), (new BlockTallGrass(type)).setHardness(0.0F).setDisplay(type.getDisplay()));
|
||||
}
|
||||
register("deadbush", (new BlockDeadBush()).setHardness(0.0F).setDisplay("Toter Busch"));
|
||||
for(BlockFlower.EnumFlowerType type : BlockFlower.EnumFlowerType.values()) {
|
||||
|
@ -254,8 +254,8 @@ public abstract class BlockRegistry {
|
|||
Block cactus = (new BlockCactus()).setHardness(0.4F).setDisplay("Kaktus");
|
||||
register("cactus", cactus);
|
||||
register("reeds", (new BlockReed()).setHardness(0.0F).setDisplay("Zuckerrohr").setTab(CheatTab.PLANTS));
|
||||
register("vine", (new BlockVine(false)).setHardness(0.2F).setDisplay("Ranken").setMiningTool(Equipment.SHEARS));
|
||||
register("swamp_vine", (new BlockVine(true)).setHardness(0.2F).setDisplay("Sumpfranken").setMiningTool(Equipment.SHEARS));
|
||||
register("vine", (new BlockVine(false)).setHardness(0.2F).setDisplay("Ranken"));
|
||||
register("swamp_vine", (new BlockVine(true)).setHardness(0.2F).setDisplay("Sumpfranken"));
|
||||
register("waterlily", (new BlockLilyPad()).setHardness(0.0F).setDisplay("Seerosenblatt"));
|
||||
|
||||
|
||||
|
@ -322,7 +322,7 @@ public abstract class BlockRegistry {
|
|||
|
||||
|
||||
for(Color color : Color.values()) {
|
||||
Block block = register(color.getName() + "_wool", (new BlockWool(color)).setHardness(0.8F).setDisplay(color.getSubject(-1) + " Wolle").setMiningTool(Equipment.SHEARS));
|
||||
Block block = register(color.getName() + "_wool", (new BlockWool(color)).setHardness(0.8F).setDisplay(color.getSubject(-1) + " Wolle"));
|
||||
register(color.getName() + "_wool_slab", (new BlockSlab(block)).setDisplay(color.getSubject(-1) + " Wollstufe"));
|
||||
register(color.getName() + "_wool_stairs", (new BlockStairs(block)).setDisplay(color.getSubject(-1) + " Wolltreppe"));
|
||||
}
|
||||
|
|
|
@ -5,7 +5,6 @@ public enum SoundEvent {
|
|||
|
||||
BLOCK_PLACE("block_place"),
|
||||
BLOCK_BREAK("block_break"),
|
||||
BLOCK_DAMAGE("block_damage"),
|
||||
GLASS_BREAK("glass_break"),
|
||||
|
||||
SPELL("spell"),
|
||||
|
|
|
@ -60,7 +60,7 @@ public class ItemTool extends Item {
|
|||
}
|
||||
|
||||
public boolean onBlockDestroyed(ItemStack stack, World world, Block block, LocalPos pos, EntityLiving player) {
|
||||
if(block.getHardness(world, pos) != 0.0f)
|
||||
if(block.getHardness() != 0)
|
||||
stack.damage(1, player);
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -208,7 +208,7 @@ public abstract class World implements IWorldAccess {
|
|||
return false;
|
||||
}
|
||||
else {
|
||||
this.playEffect(2001, pos, BlockRegistry.getId(iblockstate));
|
||||
this.playEffect(dropBlock ? 2001 : 2003, pos, BlockRegistry.getId(iblockstate));
|
||||
|
||||
if(dropBlock) {
|
||||
block.drop(this, pos, iblockstate, 0);
|
||||
|
|
|
@ -939,7 +939,7 @@ public final class WorldServer extends AWorldServer {
|
|||
private boolean destroyBlock(LocalPos pos, float power, EntityLiving source) {
|
||||
State state = this.getState(pos);
|
||||
Block block = state.getBlock();
|
||||
if(block != Blocks.air && (block.getMaterial().isLiquid() || power - (block.getRawHardness() + 0.3F) * 0.3F > 0.0F)) {
|
||||
if(block != Blocks.air && (block.getMaterial().isLiquid() || power - ((float)block.getHardness() + 0.3F) * 0.3F > 0.0F)) {
|
||||
if(block.canExplosionDrop() && this.rand.floatv() <= 1.0F / (power * power))
|
||||
block.drop(this, pos, state, 0);
|
||||
this.setState(pos, Blocks.air.getState(), 2);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue