mirror of
https://github.com/Thorfusion/Mekanism-Community-Edition.git
synced 2026-11-26 23:03:01 +00:00
Formatting and code readability cleanup (#5467)
* First pass reformatting code to be more readable (common still not done) * Replace google common collect calls with Java calls where possible * Remove a bunch of unnecessary parenthesis leaving clarifying ones * Add some missing @Nonnull annotations * Fix checking wrong type * Remove unnecessary continue/return statements and simplify comparision check * Pass exception instead of directly printing stack trace * Work on cleaning up common, through config so far * Work on cleaning up common, through integration so far * Work on cleaning up common, through network so far * Work on cleaning up common, through tier so far * Remove empty constructors that get created by default anyways * Work on cleaning up common, through transmitters so far * Work on cleaning up common, through utils so far * Finish cleaning up spacing for common
This commit is contained in:
1 parent
91ef2a5c3d
commit
0d4b50908f
909 files changed
+6234
-15623
No files matched your search
@@ -59,7 +59,6 @@ public class ItemAtomicDisassembler extends ItemEnergized {
|
||||
@Override
|
||||
public void addInformation(ItemStack itemstack, World world, List<String> list, ITooltipFlag flag) {
|
||||
super.addInformation(itemstack, world, list, flag);
|
||||
|
||||
list.add(LangUtils.localize("tooltip.mode") + ": " + EnumColor.INDIGO + getModeName(itemstack));
|
||||
list.add(LangUtils.localize("tooltip.efficiency") + ": " + EnumColor.INDIGO + getEfficiency(itemstack));
|
||||
}
|
||||
@@ -72,7 +71,6 @@ public class ItemAtomicDisassembler extends ItemEnergized {
|
||||
} else {
|
||||
target.attackEntityFrom(DamageSource.causeMobDamage(attacker), 20);
|
||||
}
|
||||
|
||||
setEnergy(itemstack, getEnergy(itemstack) - 2000);
|
||||
} else {
|
||||
if (attacker instanceof EntityPlayer) {
|
||||
@@ -80,9 +78,7 @@ public class ItemAtomicDisassembler extends ItemEnergized {
|
||||
} else {
|
||||
target.attackEntityFrom(DamageSource.causeMobDamage(attacker), 4);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -92,27 +88,20 @@ public class ItemAtomicDisassembler extends ItemEnergized {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onBlockDestroyed(ItemStack itemstack, World world, IBlockState state, BlockPos pos,
|
||||
EntityLivingBase entityliving) {
|
||||
public boolean onBlockDestroyed(ItemStack itemstack, World world, IBlockState state, BlockPos pos, EntityLivingBase entityliving) {
|
||||
if (state.getBlockHardness(world, pos) != 0.0D) {
|
||||
setEnergy(itemstack,
|
||||
getEnergy(itemstack) - (MekanismConfig.current().general.DISASSEMBLER_USAGE.val() * getEfficiency(
|
||||
itemstack)));
|
||||
setEnergy(itemstack, getEnergy(itemstack) - (MekanismConfig.current().general.DISASSEMBLER_USAGE.val() * getEfficiency(itemstack)));
|
||||
} else {
|
||||
setEnergy(itemstack, getEnergy(itemstack) - (
|
||||
MekanismConfig.current().general.DISASSEMBLER_USAGE.val() * (getEfficiency(itemstack)) / 2F));
|
||||
setEnergy(itemstack, getEnergy(itemstack) - (MekanismConfig.current().general.DISASSEMBLER_USAGE.val() * getEfficiency(itemstack) / 2F));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private RayTraceResult doRayTrace(IBlockState state, BlockPos pos, EntityPlayer player) {
|
||||
Vec3d positionEyes = player.getPositionEyes(1.0F);
|
||||
Vec3d playerLook = player.getLook(1.0F);
|
||||
double blockReachDistance = player.getAttributeMap().getAttributeInstance(EntityPlayer.REACH_DISTANCE)
|
||||
.getAttributeValue();
|
||||
Vec3d maxReach = positionEyes.add(playerLook.x * blockReachDistance, playerLook.y * blockReachDistance,
|
||||
playerLook.z * blockReachDistance);
|
||||
double blockReachDistance = player.getAttributeMap().getAttributeInstance(EntityPlayer.REACH_DISTANCE).getAttributeValue();
|
||||
Vec3d maxReach = positionEyes.add(playerLook.x * blockReachDistance, playerLook.y * blockReachDistance, playerLook.z * blockReachDistance);
|
||||
RayTraceResult res = state.collisionRayTrace(player.world, pos, playerLook, maxReach);
|
||||
//noinspection ConstantConditions - idea thinks it's nonnull due to package level annotations, but it's not
|
||||
return res != null ? res : new RayTraceResult(RayTraceResult.Type.MISS, Vec3d.ZERO, EnumFacing.UP, pos);
|
||||
@@ -121,55 +110,39 @@ public class ItemAtomicDisassembler extends ItemEnergized {
|
||||
@Override
|
||||
public boolean onBlockStartBreak(ItemStack itemstack, BlockPos pos, EntityPlayer player) {
|
||||
super.onBlockStartBreak(itemstack, pos, player);
|
||||
|
||||
if (!player.world.isRemote) {
|
||||
IBlockState state = player.world.getBlockState(pos);
|
||||
Block block = state.getBlock();
|
||||
int meta = block.getMetaFromState(state);
|
||||
|
||||
if (block == Blocks.LIT_REDSTONE_ORE) {
|
||||
block = Blocks.REDSTONE_ORE;
|
||||
}
|
||||
|
||||
RayTraceResult raytrace = doRayTrace(state, pos, player);
|
||||
ItemStack stack = block.getPickBlock(state, raytrace, player.world, pos, player);
|
||||
Coord4D orig = new Coord4D(pos, player.world);
|
||||
|
||||
List<String> names = OreDictCache.getOreDictName(stack);
|
||||
|
||||
boolean isOre = false;
|
||||
|
||||
for (String s : names) {
|
||||
if (s.startsWith("ore") || s.equals("logWood")) {
|
||||
isOre = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (getMode(itemstack) == 3 && isOre && !player.capabilities.isCreativeMode) {
|
||||
Set<Coord4D> found = new Finder(player, stack, new Coord4D(pos, player.world), raytrace).calc();
|
||||
|
||||
for (Coord4D coord : found) {
|
||||
if (coord.equals(orig) || getEnergy(itemstack) < (
|
||||
MekanismConfig.current().general.DISASSEMBLER_USAGE.val() * getEfficiency(
|
||||
itemstack))) {
|
||||
if (coord.equals(orig) || getEnergy(itemstack) < (MekanismConfig.current().general.DISASSEMBLER_USAGE.val() * getEfficiency(itemstack))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Block block2 = coord.getBlock(player.world);
|
||||
|
||||
block2.onBlockHarvested(player.world, coord.getPos(), state, player);
|
||||
player.world.playEvent(WorldEvents.BREAK_BLOCK_EFFECTS, coord.getPos(), Block.getStateId(state));
|
||||
player.world.setBlockToAir(coord.getPos());
|
||||
block2.breakBlock(player.world, coord.getPos(), state);
|
||||
block2.dropBlockAsItem(player.world, coord.getPos(), state, 0);
|
||||
|
||||
setEnergy(itemstack,
|
||||
getEnergy(itemstack) - (MekanismConfig.current().general.DISASSEMBLER_USAGE.val()
|
||||
* getEfficiency(itemstack)));
|
||||
setEnergy(itemstack, getEnergy(itemstack) - (MekanismConfig.current().general.DISASSEMBLER_USAGE.val() * getEfficiency(itemstack)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -182,35 +155,26 @@ public class ItemAtomicDisassembler extends ItemEnergized {
|
||||
@Override
|
||||
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer entityplayer, @Nonnull EnumHand hand) {
|
||||
ItemStack itemstack = entityplayer.getHeldItem(hand);
|
||||
|
||||
if (entityplayer.isSneaking()) {
|
||||
if (!world.isRemote) {
|
||||
toggleMode(itemstack);
|
||||
entityplayer.sendMessage(new TextComponentString(
|
||||
EnumColor.DARK_BLUE + Mekanism.LOG_TAG + " " + EnumColor.GREY + LangUtils
|
||||
.localize("tooltip.modeToggle")
|
||||
+ " " + EnumColor.INDIGO + getModeName(itemstack) + EnumColor.AQUA + " (" + getEfficiency(
|
||||
itemstack) + ")"));
|
||||
entityplayer.sendMessage(new TextComponentString(EnumColor.DARK_BLUE + Mekanism.LOG_TAG + " " + EnumColor.GREY + LangUtils.localize("tooltip.modeToggle")
|
||||
+ " " + EnumColor.INDIGO + getModeName(itemstack) + EnumColor.AQUA + " (" + getEfficiency(itemstack) + ")"));
|
||||
}
|
||||
|
||||
return new ActionResult<>(EnumActionResult.SUCCESS, itemstack);
|
||||
}
|
||||
|
||||
return new ActionResult<>(EnumActionResult.PASS, itemstack);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing side,
|
||||
float hitX, float hitY, float hitZ) {
|
||||
public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
|
||||
ItemStack stack = player.getHeldItem(hand);
|
||||
Block block = world.getBlockState(pos).getBlock();
|
||||
|
||||
if (!player.isSneaking() && (block == Blocks.DIRT || block == Blocks.GRASS || block == Blocks.GRASS_PATH)) {
|
||||
if (useHoe(stack, player, world, pos, side) == EnumActionResult.FAIL) {
|
||||
return EnumActionResult.FAIL;
|
||||
}
|
||||
|
||||
switch (getEfficiency(stack)) {
|
||||
case 20:
|
||||
for (int x1 = -1; x1 <= +1; x1++) {
|
||||
@@ -218,7 +182,6 @@ public class ItemAtomicDisassembler extends ItemEnergized {
|
||||
useHoe(stack, player, world, pos.add(x1, 0, z1), side);
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
case 128:
|
||||
for (int x1 = -2; x1 <= +2; x1++) {
|
||||
@@ -226,56 +189,46 @@ public class ItemAtomicDisassembler extends ItemEnergized {
|
||||
useHoe(stack, player, world, pos.add(x1, 0, z1), side);
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
return EnumActionResult.SUCCESS;
|
||||
}
|
||||
|
||||
return EnumActionResult.PASS;
|
||||
}
|
||||
|
||||
@SuppressWarnings("incomplete-switch")
|
||||
private EnumActionResult useHoe(ItemStack stack, EntityPlayer playerIn, World worldIn, BlockPos pos,
|
||||
EnumFacing facing) {
|
||||
private EnumActionResult useHoe(ItemStack stack, EntityPlayer playerIn, World worldIn, BlockPos pos, EnumFacing facing) {
|
||||
if (!playerIn.canPlayerEdit(pos.offset(facing), facing, stack)) {
|
||||
return EnumActionResult.FAIL;
|
||||
} else {
|
||||
int hook = net.minecraftforge.event.ForgeEventFactory.onHoeUse(stack, playerIn, worldIn, pos);
|
||||
if (hook != 0) {
|
||||
return hook > 0 ? EnumActionResult.SUCCESS : EnumActionResult.FAIL;
|
||||
}
|
||||
|
||||
IBlockState iblockstate = worldIn.getBlockState(pos);
|
||||
Block block = iblockstate.getBlock();
|
||||
|
||||
if (facing != EnumFacing.DOWN && worldIn.isAirBlock(pos.up())) {
|
||||
if (block == Blocks.GRASS || block == Blocks.GRASS_PATH) {
|
||||
setBlock(stack, playerIn, worldIn, pos, Blocks.FARMLAND.getDefaultState());
|
||||
return EnumActionResult.SUCCESS;
|
||||
}
|
||||
|
||||
if (block == Blocks.DIRT) {
|
||||
switch (iblockstate.getValue(BlockDirt.VARIANT)) {
|
||||
case DIRT:
|
||||
setBlock(stack, playerIn, worldIn, pos, Blocks.FARMLAND.getDefaultState());
|
||||
return EnumActionResult.SUCCESS;
|
||||
case COARSE_DIRT:
|
||||
setBlock(stack, playerIn, worldIn, pos, Blocks.DIRT.getDefaultState()
|
||||
.withProperty(BlockDirt.VARIANT, BlockDirt.DirtType.DIRT));
|
||||
return EnumActionResult.SUCCESS;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return EnumActionResult.PASS;
|
||||
}
|
||||
int hook = net.minecraftforge.event.ForgeEventFactory.onHoeUse(stack, playerIn, worldIn, pos);
|
||||
if (hook != 0) {
|
||||
return hook > 0 ? EnumActionResult.SUCCESS : EnumActionResult.FAIL;
|
||||
}
|
||||
IBlockState iblockstate = worldIn.getBlockState(pos);
|
||||
Block block = iblockstate.getBlock();
|
||||
if (facing != EnumFacing.DOWN && worldIn.isAirBlock(pos.up())) {
|
||||
if (block == Blocks.GRASS || block == Blocks.GRASS_PATH) {
|
||||
setBlock(stack, playerIn, worldIn, pos, Blocks.FARMLAND.getDefaultState());
|
||||
return EnumActionResult.SUCCESS;
|
||||
}
|
||||
if (block == Blocks.DIRT) {
|
||||
switch (iblockstate.getValue(BlockDirt.VARIANT)) {
|
||||
case DIRT:
|
||||
setBlock(stack, playerIn, worldIn, pos, Blocks.FARMLAND.getDefaultState());
|
||||
return EnumActionResult.SUCCESS;
|
||||
case COARSE_DIRT:
|
||||
setBlock(stack, playerIn, worldIn, pos, Blocks.DIRT.getDefaultState()
|
||||
.withProperty(BlockDirt.VARIANT, BlockDirt.DirtType.DIRT));
|
||||
return EnumActionResult.SUCCESS;
|
||||
}
|
||||
}
|
||||
}
|
||||
return EnumActionResult.PASS;
|
||||
}
|
||||
|
||||
protected void setBlock(ItemStack stack, EntityPlayer player, World worldIn, BlockPos pos, IBlockState state) {
|
||||
worldIn.playSound(player, pos, SoundEvents.ITEM_HOE_TILL, SoundCategory.BLOCKS, 1.0F, 1.0F);
|
||||
|
||||
if (!worldIn.isRemote) {
|
||||
worldIn.setBlockState(pos, state, 11);
|
||||
stack.damageItem(1, player);
|
||||
@@ -295,7 +248,6 @@ public class ItemAtomicDisassembler extends ItemEnergized {
|
||||
case 4:
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -305,7 +257,6 @@ public class ItemAtomicDisassembler extends ItemEnergized {
|
||||
|
||||
public String getModeName(ItemStack itemStack) {
|
||||
int mode = getMode(itemStack);
|
||||
|
||||
switch (mode) {
|
||||
case 0:
|
||||
return LangUtils.localize("tooltip.disassembler.normal");
|
||||
@@ -318,7 +269,6 @@ public class ItemAtomicDisassembler extends ItemEnergized {
|
||||
case 4:
|
||||
return LangUtils.localize("tooltip.disassembler.off");
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -336,12 +286,10 @@ public class ItemAtomicDisassembler extends ItemEnergized {
|
||||
@Deprecated
|
||||
public Multimap<String, AttributeModifier> getItemAttributeModifiers(EntityEquipmentSlot equipmentSlot) {
|
||||
Multimap<String, AttributeModifier> multimap = super.getItemAttributeModifiers(equipmentSlot);
|
||||
|
||||
if (equipmentSlot == EntityEquipmentSlot.MAINHAND) {
|
||||
multimap.put(SharedMonsterAttributes.ATTACK_SPEED.getName(),
|
||||
new AttributeModifier(ATTACK_SPEED_MODIFIER, "Weapon modifier", -2.4000000953674316D, 0));
|
||||
}
|
||||
|
||||
return multimap;
|
||||
}
|
||||
|
||||
@@ -375,18 +323,13 @@ public class ItemAtomicDisassembler extends ItemEnergized {
|
||||
if (found.contains(pointer) || found.size() > 128) {
|
||||
return;
|
||||
}
|
||||
|
||||
found.add(pointer);
|
||||
|
||||
for (EnumFacing side : EnumFacing.VALUES) {
|
||||
Coord4D coord = pointer.offset(side);
|
||||
|
||||
ItemStack blockStack = coord.getBlock(world)
|
||||
.getPickBlock(coord.getBlockState(world), rayTraceResult, world, coord.getPos(), player);
|
||||
|
||||
if (coord.exists(world) && checkID(coord.getBlock(world)) && (stack.isItemEqual(blockStack) || (
|
||||
coord.getBlock(world) == startBlock && OreDictCache.getOreDictName(stack).contains("logWood")
|
||||
&& coord.getBlockMeta(world) % 4 == stack.getItemDamage() % 4))) {
|
||||
ItemStack blockStack = coord.getBlock(world).getPickBlock(coord.getBlockState(world), rayTraceResult, world, coord.getPos(), player);
|
||||
if (coord.exists(world) && checkID(coord.getBlock(world)) &&
|
||||
(stack.isItemEqual(blockStack) || (coord.getBlock(world) == startBlock && OreDictCache.getOreDictName(stack).contains("logWood")
|
||||
&& coord.getBlockMeta(world) % 4 == stack.getItemDamage() % 4))) {
|
||||
loop(coord);
|
||||
}
|
||||
}
|
||||
@@ -394,14 +337,12 @@ public class ItemAtomicDisassembler extends ItemEnergized {
|
||||
|
||||
public Set<Coord4D> calc() {
|
||||
loop(location);
|
||||
|
||||
return found;
|
||||
}
|
||||
|
||||
public boolean checkID(Block b) {
|
||||
Block origBlock = location.getBlock(world);
|
||||
return (ignoreBlocks.get(origBlock) == null && b == origBlock) || (ignoreBlocks.get(origBlock) != null
|
||||
&& ignoreBlocks.get(origBlock).contains(b));
|
||||
return (ignoreBlocks.get(origBlock) == null && b == origBlock) || (ignoreBlocks.get(origBlock) != null && ignoreBlocks.get(origBlock).contains(b));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user