improve some instanceof expressions
This commit is contained in:
parent
9eb5f2cfd3
commit
678f37e184
7 changed files with 48 additions and 58 deletions
|
@ -238,8 +238,8 @@ public class SoundManager {
|
|||
this.sources.put(s, new Source(getBuffer(sound.getSoundLocation()), Volume.getByType(sound.getChannelType()), sound.canRepeat(), s, sound.getXPosF(), sound.getYPosF(), sound.getZPosF(), sound.getAttenuationType(), attn, volume));
|
||||
this.playingSoundsStopTime.put(s, this.playTime + 20);
|
||||
this.playingSounds.put(s, sound);
|
||||
if (sound instanceof MovingSound)
|
||||
this.tickableSounds.add((MovingSound)sound);
|
||||
if (sound instanceof MovingSound moving)
|
||||
this.tickableSounds.add(moving);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -176,8 +176,8 @@ public abstract class Gui {
|
|||
this.min_y = Math.min(this.min_y, elem.getY());
|
||||
this.max_x = Math.max(this.max_x, elem.getX() + elem.getWidth());
|
||||
this.max_y = Math.max(this.max_y, elem.getY() + elem.getHeight());
|
||||
if(elem instanceof Dropdown)
|
||||
this.add(((Dropdown)elem).getHandle());
|
||||
if(elem instanceof Dropdown drop)
|
||||
this.add(drop.getHandle());
|
||||
return elem;
|
||||
}
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ public class Dropdown<T> extends Element {
|
|||
for(T value : Dropdown.this.values) {
|
||||
if(sb.length() > 0)
|
||||
sb.append('\n');
|
||||
sb.append(value instanceof Displayable ? ((Displayable)value).getDisplay() : value.toString());
|
||||
sb.append(value instanceof Displayable disp ? disp.getDisplay() : value.toString());
|
||||
}
|
||||
this.setText(sb.toString());
|
||||
this.visible = /* this.r_dirty = */ false;
|
||||
|
@ -85,12 +85,12 @@ public class Dropdown<T> extends Element {
|
|||
this(x, y, w, h, up, values, def, init, callback, text == null ? new Formatter<Dropdown<T>>() {
|
||||
public String use(Dropdown<T> elem) {
|
||||
T value = elem.getValue();
|
||||
return value instanceof Displayable ? ((Displayable)value).getDisplay() : value.toString();
|
||||
return value instanceof Displayable disp ? disp.getDisplay() : value.toString();
|
||||
}
|
||||
} : new Formatter<Dropdown<T>>() {
|
||||
public String use(Dropdown<T> elem) {
|
||||
T value = elem.getValue();
|
||||
return String.format("%s: %s", text, value instanceof Displayable ? ((Displayable)value).getDisplay() : value.toString());
|
||||
return String.format("%s: %s", text, value instanceof Displayable disp ? disp.getDisplay() : value.toString());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@ public class Switch<T> extends Element {
|
|||
this(x, y, w, h, values, def, init, callback, new Formatter<Switch<T>>() {
|
||||
public String use(Switch<T> elem) {
|
||||
T value = elem.getValue();
|
||||
return String.format("%s: %s", text, value instanceof Displayable ? ((Displayable)value).getDisplay() : value.toString());
|
||||
return String.format("%s: %s", text, value instanceof Displayable disp ? disp.getDisplay() : value.toString());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -38,15 +38,14 @@ public class GuiForm extends Gui implements ButtonCallback {
|
|||
final String name = this.inputData[z].first();
|
||||
Object obj = this.inputData[z].second();
|
||||
int param = this.inputData[z].third();
|
||||
if(obj instanceof Boolean) {
|
||||
this.inputs[z] = this.add(new Toggle(0, 50 * z, 300, 0, (Boolean)obj, (Boolean)obj, new ToggleCallback() {
|
||||
if(obj instanceof Boolean bool) {
|
||||
this.inputs[z] = this.add(new Toggle(0, 50 * z, 300, 0, bool, bool, new ToggleCallback() {
|
||||
public void use(Toggle elem, boolean value) {
|
||||
GuiForm.this.outputData[index] = value;
|
||||
}
|
||||
}, name));
|
||||
}
|
||||
else if(obj instanceof String[]) {
|
||||
final String[] strs = (String[])obj;
|
||||
else if(obj instanceof String[] strs) {
|
||||
param = ExtMath.clampi(param, 0, strs.length - 1);
|
||||
this.inputs[z] = this.add(new Switch<String>(0, 50 * z, 300, 0, strs, strs[param], strs[param], new SwitchCallback<String>() {
|
||||
public void use(Switch<String> elem, String value) {
|
||||
|
|
|
@ -40,8 +40,7 @@ public class GuiStyle extends GuiOptions implements DropdownCallback<String>, Bu
|
|||
|
||||
protected Element addSelector(String cvar, int x, int y, int w, int h) {
|
||||
CVar cv = this.gm.getVar(cvar);
|
||||
if(cv instanceof ColorVar) {
|
||||
ColorVar color = (ColorVar)cv;
|
||||
if(cv instanceof ColorVar color) {
|
||||
if(!color.getDisplay().isEmpty())
|
||||
this.add(color.label(x, y, w));
|
||||
if(this.gm.style != Style.CUSTOM)
|
||||
|
|
|
@ -391,8 +391,8 @@ public class ClientPlayer implements IClientPlayer
|
|||
entity.setId(packetIn.getEntityID());
|
||||
this.world.addEntityToWorld(packetIn.getEntityID(), entity);
|
||||
|
||||
if(entity instanceof EntityProjectile) {
|
||||
((EntityProjectile)entity).setAcceleration((double)packetIn.getSpeedX() / 8000.0D, (double)packetIn.getSpeedY() / 8000.0D, (double)packetIn.getSpeedZ() / 8000.0D);
|
||||
if(entity instanceof EntityProjectile projectile) {
|
||||
projectile.setAcceleration((double)packetIn.getSpeedX() / 8000.0D, (double)packetIn.getSpeedY() / 8000.0D, (double)packetIn.getSpeedZ() / 8000.0D);
|
||||
}
|
||||
else if (entity.hasSpawnVelocity()) // packetIn.getData() > 0)
|
||||
{
|
||||
|
@ -492,8 +492,8 @@ public class ClientPlayer implements IClientPlayer
|
|||
{
|
||||
entity.getDataWatcher().updateWatchedObjectsFromList(packetIn.func_149376_c());
|
||||
|
||||
if(entity == this.gm.player && this.gm.open instanceof GuiChar)
|
||||
((GuiChar)this.gm.open).checkReopen();
|
||||
if(entity == this.gm.player && this.gm.open instanceof GuiChar gui)
|
||||
gui.checkReopen();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -990,16 +990,16 @@ public class ClientPlayer implements IClientPlayer
|
|||
{
|
||||
entity = this.gm.player;
|
||||
|
||||
if (entity1 instanceof EntityBoat)
|
||||
if (entity1 instanceof EntityBoat boat)
|
||||
{
|
||||
((EntityBoat)entity1).setIsBoatEmpty(false);
|
||||
boat.setIsBoatEmpty(false);
|
||||
}
|
||||
|
||||
// flag = entity.vehicle == null && entity1 != null;
|
||||
}
|
||||
else if (entity1 instanceof EntityBoat)
|
||||
else if (entity1 instanceof EntityBoat boat)
|
||||
{
|
||||
((EntityBoat)entity1).setIsBoatEmpty(true);
|
||||
boat.setIsBoatEmpty(true);
|
||||
}
|
||||
|
||||
if (entity == null)
|
||||
|
@ -1014,15 +1014,15 @@ public class ClientPlayer implements IClientPlayer
|
|||
// this.gameController.ingameGui.displayHotbar(TextColor.LIGHT_GRAY + String.format("Drücke %s zum Verlassen", this.gameController.keyBindSneak.getKeyDisplay()));
|
||||
// }
|
||||
}
|
||||
else if (packetIn.getLeash() == 1 && entity instanceof EntityLiving)
|
||||
else if (packetIn.getLeash() == 1 && entity instanceof EntityLiving living)
|
||||
{
|
||||
if (entity1 != null)
|
||||
{
|
||||
((EntityLiving)entity).setLeashedTo(entity1, false);
|
||||
living.setLeashedTo(entity1, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
((EntityLiving)entity).clearLeashed(false, false);
|
||||
living.clearLeashed(false, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1164,15 +1164,15 @@ public class ClientPlayer implements IClientPlayer
|
|||
else if ("tile".equals(id))
|
||||
{
|
||||
TileEntity tile = this.world.getTileEntity(packet.getTilePos());
|
||||
if(!(tile instanceof TileEntityDevice))
|
||||
if(!(tile instanceof TileEntityDevice dev))
|
||||
return;
|
||||
this.gm.displayGuiScreen(new GuiTile(this.gm.player.inventory, local, (TileEntityDevice)tile));
|
||||
this.gm.displayGuiScreen(new GuiTile(this.gm.player.inventory, local, dev));
|
||||
}
|
||||
else
|
||||
{
|
||||
Block block = BlockRegistry.getRegisteredBlock(id);
|
||||
if(block instanceof BlockWorkbench) {
|
||||
this.gm.displayGuiScreen(new GuiCrafting(player.inventory, player.worldObj, (BlockWorkbench)block));
|
||||
if(block instanceof BlockWorkbench bench) {
|
||||
this.gm.displayGuiScreen(new GuiCrafting(player.inventory, player.worldObj, bench));
|
||||
}
|
||||
else {
|
||||
this.gm.displayGuiScreen(new GuiChest(player.inventory, local));
|
||||
|
@ -1299,10 +1299,8 @@ public class ClientPlayer implements IClientPlayer
|
|||
{
|
||||
TileEntity tileentity = this.gm.world.getTileEntity(packetIn.getPos());
|
||||
|
||||
if (tileentity instanceof TileEntitySign)
|
||||
if (tileentity instanceof TileEntitySign tileentitysign)
|
||||
{
|
||||
TileEntitySign tileentitysign = (TileEntitySign)tileentity;
|
||||
|
||||
// if (tileentitysign.getIsEditable())
|
||||
// {
|
||||
System.arraycopy(packetIn.getLines(), 0, tileentitysign.signText, 0, 4);
|
||||
|
@ -1512,11 +1510,11 @@ public class ClientPlayer implements IClientPlayer
|
|||
NetHandler.checkThread(packetIn, this, this.gm, this.world);
|
||||
Entity entity = this.world.getEntityByID(packetIn.getEntityId());
|
||||
|
||||
if (entity instanceof EntityLiving)
|
||||
if (entity instanceof EntityLiving living)
|
||||
{
|
||||
PotionEffect potioneffect = new PotionEffect(packetIn.getEffectId(), packetIn.getDuration(), packetIn.getAmplifier(), false, packetIn.hasParticles())
|
||||
.setRemaining(packetIn.getRemaining());
|
||||
((EntityLiving)entity).addEffect(potioneffect);
|
||||
living.addEffect(potioneffect);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1589,9 +1587,9 @@ public class ClientPlayer implements IClientPlayer
|
|||
NetHandler.checkThread(packetIn, this, this.gm, this.world);
|
||||
Entity entity = this.world.getEntityByID(packetIn.getEntityId());
|
||||
|
||||
if (entity instanceof EntityLiving)
|
||||
if (entity instanceof EntityLiving living)
|
||||
{
|
||||
((EntityLiving)entity).removeEffectClient(packetIn.getEffectId());
|
||||
living.removeEffectClient(packetIn.getEffectId());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1661,9 +1659,8 @@ public class ClientPlayer implements IClientPlayer
|
|||
NetHandler.checkThread(packetIn, this, this.gm, this.world);
|
||||
String[] astring = packetIn.func_149630_c();
|
||||
// this.gameController.complete(astring);
|
||||
if (this.gm.open instanceof GuiConsole)
|
||||
if (this.gm.open instanceof GuiConsole guichat)
|
||||
{
|
||||
GuiConsole guichat = (GuiConsole)this.gm.open;
|
||||
guichat.onAutocompleteResponse(astring);
|
||||
}
|
||||
}
|
||||
|
@ -1886,30 +1883,25 @@ public class ClientPlayer implements IClientPlayer
|
|||
|
||||
if (entity != null)
|
||||
{
|
||||
if (!(entity instanceof EntityLiving))
|
||||
{
|
||||
if (!(entity instanceof EntityLiving living))
|
||||
throw new IllegalStateException("Server tried to update attributes of a non-living entity (actually: " + entity + ")");
|
||||
}
|
||||
else
|
||||
AttributeMap baseattributemap = living.getAttributeMap();
|
||||
|
||||
for (SPacketEntityProperties.Snapshot s20packetentityproperties$snapshot : packetIn.func_149441_d())
|
||||
{
|
||||
AttributeMap baseattributemap = ((EntityLiving)entity).getAttributeMap();
|
||||
AttributeInstance iattributeinstance = baseattributemap.getAttributeInstanceByName(s20packetentityproperties$snapshot.func_151409_a());
|
||||
|
||||
for (SPacketEntityProperties.Snapshot s20packetentityproperties$snapshot : packetIn.func_149441_d())
|
||||
if (iattributeinstance == null)
|
||||
{
|
||||
AttributeInstance iattributeinstance = baseattributemap.getAttributeInstanceByName(s20packetentityproperties$snapshot.func_151409_a());
|
||||
iattributeinstance = baseattributemap.registerAttribute(Attribute.getAttribute(s20packetentityproperties$snapshot.func_151409_a()));
|
||||
}
|
||||
|
||||
if (iattributeinstance == null)
|
||||
{
|
||||
iattributeinstance = baseattributemap.registerAttribute(Attribute.getAttribute(s20packetentityproperties$snapshot.func_151409_a()));
|
||||
}
|
||||
iattributeinstance.setBaseValue(s20packetentityproperties$snapshot.func_151410_b());
|
||||
iattributeinstance.removeAllModifiers();
|
||||
|
||||
iattributeinstance.setBaseValue(s20packetentityproperties$snapshot.func_151410_b());
|
||||
iattributeinstance.removeAllModifiers();
|
||||
|
||||
for (AttributeModifier attributemodifier : s20packetentityproperties$snapshot.func_151408_c())
|
||||
{
|
||||
iattributeinstance.applyModifier(attributemodifier);
|
||||
}
|
||||
for (AttributeModifier attributemodifier : s20packetentityproperties$snapshot.func_151408_c())
|
||||
{
|
||||
iattributeinstance.applyModifier(attributemodifier);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1950,11 +1942,11 @@ public class ClientPlayer implements IClientPlayer
|
|||
int i = packetIn.getWindowId();
|
||||
Gui gui = this.gm.open;
|
||||
|
||||
if (gui != null && gui instanceof GuiMerchant && i == this.gm.player.openContainer.windowId)
|
||||
if (gui != null && gui instanceof GuiMerchant merchant && i == this.gm.player.openContainer.windowId)
|
||||
{
|
||||
// NpcMerchant imerchant = ((GuiMerchant)guiscreen).getMerchant();
|
||||
MerchantRecipeList merchantrecipelist = packetIn.getTrades();
|
||||
((GuiMerchant)gui).setRecipes(merchantrecipelist);
|
||||
merchant.setRecipes(merchantrecipelist);
|
||||
}
|
||||
}
|
||||
catch (Exception exception)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue