Code cleanup

This commit is contained in:
Unknown 2019-09-22 13:45:18 +02:00 committed by unknown
parent ceca506ca4
commit 032625f0d4
18 changed files with 61 additions and 49 deletions

View file

@ -45,7 +45,7 @@ public class CommonProxy {
return null;
}
public static EntityPlayer getFakePlayer(final UUID uuidPlayer, final WorldServer world, final BlockPos blockPos) {
public static EntityPlayer getFakePlayer(@Nullable final UUID uuidPlayer, @Nonnull final WorldServer world, @Nonnull final BlockPos blockPos) {
final EntityPlayer entityPlayer = uuidPlayer == null ? null : getPlayer(world, uuidPlayer);
final GameProfile gameProfile = entityPlayer == null ? WarpDrive.gameProfile : entityPlayer.getGameProfile();
WeakReference<EntityPlayer> weakFakePlayer = fakePlayers.get(gameProfile);

View file

@ -16,6 +16,7 @@ import javax.annotation.Nullable;
import net.minecraft.block.Block;
import net.minecraft.block.BlockLiquid;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.command.CommandException;
import net.minecraft.command.EntitySelector;
@ -498,6 +499,21 @@ public class Commons {
}
}
public static String format(@Nonnull final Material material) {
String name = material.toString();
try {
for (final Field field : Material.class.getDeclaredFields()) {
if (field.get(null) == material) {
name = field.getName();
break;
}
}
} catch (final Exception exception) {
// no operation
}
return name;
}
@Nonnull
public static String sanitizeFileName(@Nonnull final String name) {
return name.replace("/", "")

View file

@ -1,6 +1,7 @@
package cr0s.warpdrive.api;
public interface IControlChannel {
int CONTROL_CHANNEL_MIN = 0;
int CONTROL_CHANNEL_MAX = 0xFFFFFFF; // 268435455
String CONTROL_CHANNEL_TAG = "controlChannel";

View file

@ -1,6 +1,7 @@
package cr0s.warpdrive.api;
public interface IVideoChannel {
int VIDEO_CHANNEL_MIN = 0;
int VIDEO_CHANNEL_MAX = 0xFFFFFFF; // 268435455
String VIDEO_CHANNEL_TAG = "videoChannel";

View file

@ -316,7 +316,8 @@ public abstract class TileEntityAbstractInterfaced extends TileEntityAbstractBas
@Override
public Integer[] getVersion() {
if (WarpDriveConfig.LOGGING_LUA) {
WarpDrive.logger.info(String.format("Version is %s isDev %s", WarpDrive.VERSION, WarpDrive.isDev));
WarpDrive.logger.info(String.format("Version is %s isDev %s",
WarpDrive.VERSION, WarpDrive.isDev ));
}
String[] strings = WarpDrive.VERSION.split("-");
if (WarpDrive.isDev) {

View file

@ -99,8 +99,8 @@ public class TileEntityLaser extends TileEntityAbstractLaser implements IBeamFre
delayTicks++;
if ( isEmitting
&& ( (beamFrequency != BEAM_FREQUENCY_SCANNING && delayTicks > WarpDriveConfig.LASER_CANNON_EMIT_FIRE_DELAY_TICKS)
|| (beamFrequency == BEAM_FREQUENCY_SCANNING && delayTicks > WarpDriveConfig.LASER_CANNON_EMIT_SCAN_DELAY_TICKS))) {
&& ( (beamFrequency != IBeamFrequency.BEAM_FREQUENCY_SCANNING && delayTicks > WarpDriveConfig.LASER_CANNON_EMIT_FIRE_DELAY_TICKS)
|| (beamFrequency == IBeamFrequency.BEAM_FREQUENCY_SCANNING && delayTicks > WarpDriveConfig.LASER_CANNON_EMIT_SCAN_DELAY_TICKS) )) {
delayTicks = 0;
isEmitting = false;
final int beamEnergy = Math.min(
@ -346,7 +346,7 @@ public class TileEntityLaser extends TileEntityAbstractLaser implements IBeamFre
playSoundCorrespondsEnergy(energy);
// This is a scanning beam, do not deal damage to block nor entity
if (beamFrequency == BEAM_FREQUENCY_SCANNING) {
if (beamFrequency == IBeamFrequency.BEAM_FREQUENCY_SCANNING) {
final RayTraceResult mopResult = rayTraceBlocks(world, vSource.toVec3d(), vReachPoint.toVec3d(), beamFrequency,
false, true, false);
@ -385,7 +385,7 @@ public class TileEntityLaser extends TileEntityAbstractLaser implements IBeamFre
if (WarpDriveConfig.LOGGING_WEAPON) {
WarpDrive.logger.info(String.format("Entity hits are (%d) %s",
(entityHits == null) ? 0 : entityHits.size(), entityHits));
(entityHits == null) ? 0 : entityHits.size(), entityHits ));
}
Vector3 vHitPoint = vReachPoint.clone();
@ -481,7 +481,6 @@ public class TileEntityLaser extends TileEntityAbstractLaser implements IBeamFre
}
final IBlockState blockState = world.getBlockState(blockHit.getBlockPos());
// int blockMeta = world.getBlockMetadata(hit.blockX, hit.blockY, hit.blockZ);
// get hardness and blast resistance
float hardness = -2.0F;
if (WarpDrive.fieldBlockHardness != null) {
@ -722,14 +721,14 @@ public class TileEntityLaser extends TileEntityAbstractLaser implements IBeamFre
@Override
public void readFromNBT(final NBTTagCompound tagCompound) {
super.readFromNBT(tagCompound);
setBeamFrequency(tagCompound.getInteger(BEAM_FREQUENCY_TAG));
setBeamFrequency(tagCompound.getInteger(IBeamFrequency.BEAM_FREQUENCY_TAG));
}
@Nonnull
@Override
public NBTTagCompound writeToNBT(NBTTagCompound tagCompound) {
tagCompound = super.writeToNBT(tagCompound);
tagCompound.setInteger(BEAM_FREQUENCY_TAG, beamFrequency);
tagCompound.setInteger(IBeamFrequency.BEAM_FREQUENCY_TAG, beamFrequency);
return tagCompound;
}

View file

@ -400,12 +400,11 @@ public class BlockForceField extends BlockAbstractForceField implements IDamageR
Commons.format(world, blockPos), exploder, explosion ));
new ConcurrentModificationException().printStackTrace();
}
WarpDrive.logger.error(String.format("Explosion check %s from exploder %s explosion %s",
WarpDrive.logger.info(String.format("Explosion check %s from exploder %s explosion %s",
Commons.format(world, blockPos), exploder, explosion ));
}
// find explosion strength, defaults to no effect
double strength = 0.0D;
if ( exploder == null
&& vExplosion.x == Math.rint(vExplosion.x)
&& vExplosion.y == Math.rint(vExplosion.y)
@ -423,6 +422,7 @@ public class BlockForceField extends BlockAbstractForceField implements IDamageR
return 2.0F * super.getExplosionResistance(world, blockPos, exploder, explosion);
}
double strength = 0.0D;
if (exploder != null) {
final String nameExploder = exploder.getClass().toString();
switch (nameExploder) {
@ -430,7 +430,7 @@ public class BlockForceField extends BlockAbstractForceField implements IDamageR
case "class net.minecraft.entity.item.EntityEnderCrystal": strength = 6.0D; break;
case "class net.minecraft.entity.item.EntityMinecartTNT": strength = 4.0D; break;
case "class net.minecraft.entity.item.EntityTNTPrimed": strength = 5.0D; break;
case "class net.minecraft.entity.monster.EntityCreeper": strength = 3.0D; break; // *2 for powered ones
case "class net.minecraft.entity.monster.EntityCreeper": strength = 3.0D; break; // Normal is 3.0, powered ones is *2
// Applied Energistics Tiny TNT
case "class appeng.entity.EntityTinyTNTPrimed": strength = 0.2D; break;

View file

@ -100,10 +100,10 @@ public abstract class TileEntityAbstractForceField extends TileEntityAbstractEne
}
@Override
public void readFromNBT(final NBTTagCompound tagCompound) {
public void readFromNBT(final NBTTagCompound tagCompound) {
super.readFromNBT(tagCompound);
setBeamFrequency(tagCompound.getInteger(BEAM_FREQUENCY_TAG));
setBeamFrequency(tagCompound.getInteger(IBeamFrequency.BEAM_FREQUENCY_TAG));
isConnected = tagCompound.getBoolean("isConnected");
}
@ -112,7 +112,7 @@ public abstract class TileEntityAbstractForceField extends TileEntityAbstractEne
public NBTTagCompound writeToNBT(NBTTagCompound tagCompound) {
tagCompound = super.writeToNBT(tagCompound);
tagCompound.setInteger(BEAM_FREQUENCY_TAG, beamFrequency);
tagCompound.setInteger(IBeamFrequency.BEAM_FREQUENCY_TAG, beamFrequency);
tagCompound.setBoolean("isConnected", isConnected);
return tagCompound;
}

View file

@ -1133,12 +1133,14 @@ public class TileEntityShipCore extends TileEntityAbstractShipController impleme
@Override
public NBTTagCompound getUpdateTag() {
final NBTTagCompound tagCompound = super.getUpdateTag();
tagCompound.setInteger("minX", minX);
tagCompound.setInteger("maxX", maxX);
tagCompound.setInteger("minY", minY);
tagCompound.setInteger("maxY", maxY);
tagCompound.setInteger("minZ", minZ);
tagCompound.setInteger("maxZ", maxZ);
return tagCompound;
}
@ -1154,6 +1156,7 @@ public class TileEntityShipCore extends TileEntityAbstractShipController impleme
maxY = tagCompound.getInteger("maxY");
minZ = tagCompound.getInteger("minZ");
maxZ = tagCompound.getInteger("maxZ");
cache_aabbArea = null;
}

View file

@ -54,7 +54,8 @@ public class TileEntityLaserCamera extends TileEntityLaser implements IVideoChan
if (registryUpdateTicks <= 0) {
registryUpdateTicks = REGISTRY_UPDATE_INTERVAL_TICKS;
if (WarpDriveConfig.LOGGING_VIDEO_CHANNEL) {
WarpDrive.logger.info(this + " Updating registry (" + videoChannel + ")");
WarpDrive.logger.info(String.format("%s Updating registry (%d)",
this, videoChannel ));
}
WarpDrive.cameras.updateInRegistry(world, pos, videoChannel, EnumCameraType.LASER_CAMERA);
}
@ -71,7 +72,8 @@ public class TileEntityLaserCamera extends TileEntityLaser implements IVideoChan
if (videoChannel != parVideoChannel && (parVideoChannel <= VIDEO_CHANNEL_MAX) && (parVideoChannel > VIDEO_CHANNEL_MIN)) {
videoChannel = parVideoChannel;
if (WarpDriveConfig.LOGGING_VIDEO_CHANNEL) {
WarpDrive.logger.info(this + " Video channel updated from " + videoChannel + " to " + parVideoChannel);
WarpDrive.logger.info(String.format("%s Video channel updated from %d to %d",
this, videoChannelOld, parVideoChannel ));
}
markDirty();
// force update through main thread since CC & OC are running outside the main thread

View file

@ -676,15 +676,15 @@ public class Dictionary {
|| block instanceof BlockHullStairs
|| BLOCKS_ANCHOR.contains(block) ) ) {
WarpDrive.logger.warn(String.format("Warning: non-anchor block with high blast resistance %s %s (%.2f)",
resourceLocation, block, blastResistance));
resourceLocation, block, blastResistance ));
block.setResistance(WarpDriveConfig.G_BLAST_RESISTANCE_CAP * 5.0F / 3.0F);
final float blastResistance_new = block.getExplosionResistance(null);
if (blastResistance_new <= WarpDriveConfig.G_BLAST_RESISTANCE_CAP) {
WarpDrive.logger.warn(String.format("Adjusted blast resistance of %s %s from %.2f to %.2f",
resourceLocation, block, blastResistance, blastResistance_new));
resourceLocation, block, blastResistance, blastResistance_new ));
} else {
WarpDrive.logger.error(String.format("Blacklisting block with high blast resistance %s %s (%.2f)",
resourceLocation, block, blastResistance));
resourceLocation, block, blastResistance ));
BLOCKS_ANCHOR.add(block);
BLOCKS_STOPMINING.add(block);
}

View file

@ -764,7 +764,7 @@ public class WarpDriveConfig {
G_ENTITY_CAMERA_ID = Commons.clamp(Integer.MIN_VALUE, Integer.MAX_VALUE,
config.get("general", "entity_camera_id", G_ENTITY_CAMERA_ID, "Entity camera ID").getInt());
G_ENTITY_PARTICLE_BUNCH_ID = Commons.clamp(Integer.MIN_VALUE, Integer.MAX_VALUE,
config.get("general", "entity_particle_bunch_id", G_ENTITY_PARTICLE_BUNCH_ID, "Entity particle bunch ID").getInt());
config.get("general", "entity_particle_bunch_id", G_ENTITY_PARTICLE_BUNCH_ID, "Entity particle bunch ID").getInt());
G_LUA_SCRIPTS = Commons.clamp(0, 2,
config.get("general", "lua_scripts", G_LUA_SCRIPTS,

View file

@ -21,7 +21,6 @@ import java.util.Set;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.DamageSource;
import net.minecraft.util.EnumFacing;
@ -307,12 +306,14 @@ public class ForceFieldSetup extends GlobalPosition {
int countdown = 0;
final TileEntity tileEntity = world.getTileEntity(new BlockPos(x, y, z));
if (tileEntity instanceof TileEntityForceFieldProjector) {
if (((TileEntityForceFieldProjector)tileEntity).onEntityInteracted(entity.getUniqueID())) {
if (((TileEntityForceFieldProjector) tileEntity).onEntityInteracted(entity.getUniqueID())) {
for (final Map.Entry<IForceFieldUpgradeEffector, Float> entry : upgrades.entrySet()) {
Float value = entry.getValue();
if (entry.getKey() == EnumForceFieldUpgrade.COOLING || entry.getKey() == EnumForceFieldUpgrade.HEATING) {
if ( entry.getKey() == EnumForceFieldUpgrade.COOLING
|| entry.getKey() == EnumForceFieldUpgrade.HEATING ) {
value = temperatureLevel;
} else if (entry.getKey() == EnumForceFieldUpgrade.ATTRACTION || entry.getKey() == EnumForceFieldUpgrade.REPULSION) {
} else if ( entry.getKey() == EnumForceFieldUpgrade.ATTRACTION
|| entry.getKey() == EnumForceFieldUpgrade.REPULSION ) {
value = accelerationLevel;
}
countdown += entry.getKey().onEntityEffect(value, world, x, y, z, blockPos, entity);

View file

@ -93,7 +93,7 @@ public class MovingEntity {
try {
final DataOutputLength dataOutputLength = new DataOutputLength();
CompressedStreamTools.write(tagCompound, dataOutputLength);
if (WarpDrive.isDev) {
if (WarpDrive.isDev && WarpDriveConfig.LOGGING_TRANSPORTER) {
WarpDrive.logger.info(String.format("Entity %s estimated mass is %d",
entity, dataOutputLength.getLength()));
}

View file

@ -585,9 +585,6 @@ public class JumpSequencer extends AbstractSequencer {
schematic.setTag("ship", tagCompoundShip);
WarpDrive.logger.info(this + " Saving ship state prior to jump in " + schematicFileName);
Commons.writeNBTToFile(schematicFileName, schematic);
if (WarpDriveConfig.LOGGING_JUMP && WarpDrive.isDev) {
WarpDrive.logger.info(this + " Ship saved as " + schematicFileName);
}
} catch (final Exception exception) {
exception.printStackTrace();
}

View file

@ -7,7 +7,6 @@ import cr0s.warpdrive.config.WarpDriveConfig;
import javax.annotation.Nonnull;
import java.lang.reflect.Field;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
@ -215,13 +214,7 @@ public class TooltipHandler {
if (WarpDriveConfig.TOOLTIP_ADD_BLOCK_MATERIAL.isEnabled(isSneaking, isCreativeMode)) {
try {
final Material material = blockState.getMaterial();
String name = material.toString();
for (final Field field : Material.class.getDeclaredFields()) {
if (field.get(null) == material) {
name = field.getName();
break;
}
}
final String name = Commons.format(material);
Commons.addTooltip(event.getToolTip(), String.format("§8Material is %s",
name ));
} catch (final Exception exception) {

View file

@ -55,7 +55,7 @@ public class RenderCommons {
public static int drawSplashAlarm(final int scaledWidth, final int scaledHeight, final String title, final String message) {
// compute animation clock
final double cycle = ((System.nanoTime() / 1000) % 0x200000) / (double) 0x200000;
final double cycle = ((System.nanoTime() / 1000L) % 0x200000) / (double) 0x200000;
// start rendering
GlStateManager.pushMatrix();
@ -66,7 +66,7 @@ public class RenderCommons {
// bold title, single line, centered, with shadows
final String textTitle = Commons.updateEscapeCodes("§l" + new TextComponentTranslation(title).getFormattedText());
minecraft.fontRenderer.drawString(textTitle,
scaledWidth / 4 - minecraft.fontRenderer.getStringWidth(textTitle) / 2,
scaledWidth / 4.0F - minecraft.fontRenderer.getStringWidth(textTitle) / 2.0F,
y - minecraft.fontRenderer.FONT_HEIGHT,
Commons.colorARGBtoInt(230, 255, 32, 24),
true);
@ -75,11 +75,10 @@ public class RenderCommons {
final String textMessage = Commons.updateEscapeCodes(new TextComponentTranslation(message).getFormattedText());
final int alpha = 160 + (int) (85.0D * Math.sin(cycle * 2 * Math.PI));
@SuppressWarnings("unchecked")
final List<String> listMessages = minecraft.fontRenderer.listFormattedStringToWidth(textMessage, scaledWidth / 2);
for (final String textLine : listMessages) {
minecraft.fontRenderer.drawString(textLine,
scaledWidth / 4 - minecraft.fontRenderer.getStringWidth(textLine) / 2,
scaledWidth / 4.0F - minecraft.fontRenderer.getStringWidth(textLine) / 2.0F,
y,
Commons.colorARGBtoInt(alpha, 192, 64, 48),
false);
@ -100,7 +99,6 @@ public class RenderCommons {
final String text_formatted = Commons.updateEscapeCodes(formatPrefix + new TextComponentTranslation(text).getFormattedText());
final int scaled_box_width = Math.max(widthTextMin, Math.round(widthTextRatio * screen_width)) + 2 * TEXT_BORDER;
@SuppressWarnings("unchecked")
final List<String> listLines = minecraft.fontRenderer.listFormattedStringToWidth(text_formatted, scaled_box_width - 2 * TEXT_BORDER);
final int scaled_box_height = listLines.size() * minecraft.fontRenderer.FONT_HEIGHT + 2 * TEXT_BORDER;
@ -148,18 +146,16 @@ public class RenderCommons {
public static void drawText(final int screen_width, final int screen_height, final String textHeader, final String textContent,
final float scale, final String formatHeader, final int colorBackground, final int colorText, final boolean hasHeaderShadow,
final EnumDisplayAlignment enumScreenAnchor, final int xOffset, final int yOffset,
final EnumDisplayAlignment enumTextAlignment, final float widthTextRatio, final int widthTextMin) {
@Nonnull final EnumDisplayAlignment enumScreenAnchor, final int xOffset, final int yOffset,
@Nonnull final EnumDisplayAlignment enumTextAlignment, final float widthTextRatio, final int widthTextMin) {
// prepare the string box content and dimensions
final String header_formatted = Commons.updateEscapeCodes(new TextComponentTranslation(textHeader, formatHeader).getFormattedText());
final String content_formatted = Commons.updateEscapeCodes(new TextComponentTranslation(textContent).getFormattedText());
final int scaled_box_width = Math.max(widthTextMin, Math.round(widthTextRatio * screen_width)) + 2 * TEXT_BORDER;
@SuppressWarnings("unchecked")
final List<String> listHeaderLines =
header_formatted.isEmpty() ? new ArrayList<>(0)
: minecraft.fontRenderer.listFormattedStringToWidth(header_formatted, scaled_box_width - 2 * TEXT_BORDER);
@SuppressWarnings("unchecked")
final List<String> listContentLines =
content_formatted.isEmpty() ? new ArrayList<>(0)
: minecraft.fontRenderer.listFormattedStringToWidth(content_formatted, scaled_box_width - 2 * TEXT_BORDER);

View file

@ -7,12 +7,14 @@ protected net.minecraft.client.gui.FontRenderer * # all of it
public net.minecraft.entity.projectile.EntityFishHook * # (nearly) literally everything is private
# protected net.minecraft.entity.player.EntityPlayer field_71072_f # itemInUseCount
public net.minecraft.item.ItemPickaxe field_150915_c # blocksEffectiveAgainst
public net.minecraft.item.ItemSpade field_150916_c # blocksEffectiveAgainst
public net.minecraft.item.ItemAxe field_150917_c # blocksEffectiveAgainst
# public net.minecraft.item.ItemPickaxe field_150915_c # blocksEffectiveAgainst
# public net.minecraft.item.ItemSpade field_150916_c # blocksEffectiveAgainst
# public net.minecraft.item.ItemAxe field_150917_c # blocksEffectiveAgainst
# public net.minecraft.util.RegistrySimple field_82596_a # registryObjects
# public-f net.minecraft.util.RegistryNamespaced field_148759_a # underlyingIntegerMap
# public net.minecraft.world.World field_72998_d # collidingBoundingBoxes
# World transition
public net.minecraft.entity.player.EntityPlayerMP field_184851_cj # invulnerableDimensionChange
public net.minecraft.network.NetHandlerPlayServer func_184342_d()V # captureCurrentPosition