diff --git a/build.gradle b/build.gradle index d3423764..b190c37e 100644 --- a/build.gradle +++ b/build.gradle @@ -137,7 +137,7 @@ processResources { gradle.projectsEvaluated { tasks.withType(JavaCompile) { - options.compilerArgs << "-Xlint" << "-Xlint:-rawtypes" + options.compilerArgs << "-Xlint" << "-Xlint:-rawtypes" << "-Xlint:-processing" } } diff --git a/src/main/java/org/squiddev/plethora/gameplay/ConfigGameplay.java b/src/main/java/org/squiddev/plethora/gameplay/ConfigGameplay.java index 854bbf95..3624d0d5 100644 --- a/src/main/java/org/squiddev/plethora/gameplay/ConfigGameplay.java +++ b/src/main/java/org/squiddev/plethora/gameplay/ConfigGameplay.java @@ -86,6 +86,14 @@ public static class Kinetic { @DefaultBoolean(true) public static boolean launchFallReset; + /** + * Whether to reset the floating timer after launching. + * + * This means the player will not be kicked for flying after using the kinetic augment a lot. + */ + @DefaultBoolean(true) + public static boolean launchFloatReset; + /** * The value to scale the velocity by when flying, helps limit how fast the player can go. */ diff --git a/src/main/java/org/squiddev/plethora/gameplay/client/RenderHelpers.java b/src/main/java/org/squiddev/plethora/gameplay/client/RenderHelpers.java index f49e0b98..eee963ac 100644 --- a/src/main/java/org/squiddev/plethora/gameplay/client/RenderHelpers.java +++ b/src/main/java/org/squiddev/plethora/gameplay/client/RenderHelpers.java @@ -6,9 +6,15 @@ import net.minecraft.client.renderer.VertexBuffer; import net.minecraft.client.renderer.block.model.BakedQuad; import net.minecraft.client.renderer.block.model.IBakedModel; +import net.minecraft.client.renderer.block.model.ModelResourceLocation; import net.minecraft.client.renderer.texture.TextureMap; import net.minecraft.client.renderer.vertex.DefaultVertexFormats; import net.minecraft.util.EnumFacing; +import net.minecraft.util.ResourceLocation; +import net.minecraftforge.client.event.ModelBakeEvent; +import net.minecraftforge.client.model.IModel; +import net.minecraftforge.client.model.ModelLoader; +import net.minecraftforge.client.model.ModelLoaderRegistry; import net.minecraftforge.client.model.pipeline.LightUtil; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; @@ -61,4 +67,10 @@ public static ItemModelMesher getMesher() { } return mesher; } + + public static void loadModel(ModelBakeEvent event, String mod, String name) { + IModel model = ModelLoaderRegistry.getModelOrMissing(new ResourceLocation(mod, "block/" + name)); + IBakedModel bakedModel = model.bake(model.getDefaultState(), DefaultVertexFormats.ITEM, ModelLoader.defaultTextureGetter()); + event.getModelRegistry().putObject(new ModelResourceLocation(mod + ":" + name, "inventory"), bakedModel); + } } diff --git a/src/main/java/org/squiddev/plethora/gameplay/minecart/CommandAPI.java b/src/main/java/org/squiddev/plethora/gameplay/minecart/CommandAPI.java index 7ed48ae3..66ff5d1d 100644 --- a/src/main/java/org/squiddev/plethora/gameplay/minecart/CommandAPI.java +++ b/src/main/java/org/squiddev/plethora/gameplay/minecart/CommandAPI.java @@ -20,7 +20,6 @@ import net.minecraft.util.math.Vec3d; import net.minecraft.util.text.ITextComponent; import net.minecraft.world.World; -import net.minecraft.world.WorldServer; import org.squiddev.plethora.utils.DebugLogger; import javax.annotation.Nonnull; @@ -39,7 +38,7 @@ public class CommandAPI extends CommandBlockBaseLogic implements ILuaAPI { public CommandAPI(Entity entity) { this.entity = entity; - this.server = ((WorldServer) entity.getEntityWorld()).getMinecraftServer(); + this.server = entity.getEntityWorld().getMinecraftServer(); } @Override @@ -78,7 +77,7 @@ private Object getBlockInfo(World world, BlockPos pos) { table.put("metadata", metadata); Map stateTable = Maps.newHashMap(); - for (Map.Entry, ?> entry : block.getActualState(state, world, pos).getProperties().entrySet()) { + for (Map.Entry, ?> entry : state.getActualState(world, pos).getProperties().entrySet()) { String propertyName = entry.getKey().getName(); Object value = entry.getValue(); if (value instanceof String || value instanceof Number || value instanceof Boolean) { @@ -103,7 +102,7 @@ public Object[] callMethod(ILuaContext context, int method, Object[] arguments) return context.executeMainThreadTask(new ILuaTask() { public Object[] execute() throws LuaException { - return CommandAPI.this.doCommand(command); + return doCommand(command); } }); } @@ -115,7 +114,7 @@ public Object[] execute() long taskID = context.issueMainThreadTask(new ILuaTask() { public Object[] execute() throws LuaException { - return CommandAPI.this.doCommand(command); + return doCommand(command); } }); return new Object[]{taskID}; @@ -178,7 +177,7 @@ public Object[] execute() for (int z = min.getZ(); z <= max.getZ(); z++) { for (int x = min.getX(); x <= max.getX(); x++) { BlockPos pos = new BlockPos(x, y, z); - results.put(i++, CommandAPI.this.getBlockInfo(world, pos)); + results.put(i++, getBlockInfo(world, pos)); } } } @@ -198,7 +197,7 @@ public Object[] execute() World world = entity.getEntityWorld(); BlockPos position = new BlockPos(x, y, z); if (WorldUtil.isBlockInWorld(world, position)) { - return new Object[]{CommandAPI.this.getBlockInfo(world, position)}; + return new Object[]{getBlockInfo(world, position)}; } throw new LuaException("Co-ordinates out or range"); } diff --git a/src/main/java/org/squiddev/plethora/gameplay/minecart/EntityMinecartComputer.java b/src/main/java/org/squiddev/plethora/gameplay/minecart/EntityMinecartComputer.java index 891064c9..d3a08ff3 100644 --- a/src/main/java/org/squiddev/plethora/gameplay/minecart/EntityMinecartComputer.java +++ b/src/main/java/org/squiddev/plethora/gameplay/minecart/EntityMinecartComputer.java @@ -501,8 +501,8 @@ private Matrix4f getTranslationMatrix(float partialTicks) { if (offsetPos != null) { final double offset = 0.3; - Vec3d posOff = getPosOffset(x, y, z, offset); - Vec3d negOff = getPosOffset(x, y, z, -offset); + Vec3d posOff = MinecartHelpers.getPosOffset(this, x, y, z, offset); + Vec3d negOff = MinecartHelpers.getPosOffset(this, x, y, z, -offset); if (posOff == null) posOff = offsetPos; if (negOff == null) negOff = offsetPos; @@ -720,6 +720,7 @@ public void drawHighlight(DrawBlockHighlightEvent event) { } @Override + @SideOnly(Side.CLIENT) public IMessage onMessage(final MessageMinecartSlot message, final MessageContext ctx) { // We schedule this to run on the main thread so the entity is actually // loaded by this point. diff --git a/src/main/java/org/squiddev/plethora/gameplay/minecart/MinecartHelpers.java b/src/main/java/org/squiddev/plethora/gameplay/minecart/MinecartHelpers.java new file mode 100644 index 00000000..21f2df05 --- /dev/null +++ b/src/main/java/org/squiddev/plethora/gameplay/minecart/MinecartHelpers.java @@ -0,0 +1,69 @@ +package org.squiddev.plethora.gameplay.minecart; + +import net.minecraft.block.BlockRailBase; +import net.minecraft.block.state.IBlockState; +import net.minecraft.entity.item.EntityMinecart; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.MathHelper; +import net.minecraft.util.math.Vec3d; +import net.minecraftforge.fml.common.ObfuscationReflectionHelper; + +public class MinecartHelpers { + private static int[][][] matrix; + + private static int[][][] getMatrix() { + if (matrix == null) { + matrix = ObfuscationReflectionHelper.getPrivateValue(EntityMinecart.class, null, "field_70500_g"); + } + + return matrix; + } + + /** + * Get the position offset of the minecart + * + * @param minecart The minecart to get the position of + * @param x Interpolated x position of minecart + * @param y Interpolated y position of minecart + * @param z Interpolated z position of minecart + * @param offset Direction to offset in + * @return The offfset position + * @see EntityMinecart#getPosOffset(double, double, double, double) + */ + public static Vec3d getPosOffset(EntityMinecart minecart, double x, double y, double z, double offset) { + int xf = MathHelper.floor_double(x); + int yf = MathHelper.floor_double(y); + int zf = MathHelper.floor_double(z); + + if (BlockRailBase.isRailBlock(minecart.worldObj, new BlockPos(xf, yf - 1, zf))) --yf; + + IBlockState block = minecart.worldObj.getBlockState(new BlockPos(xf, yf, zf)); + + if (BlockRailBase.isRailBlock(block)) { + BlockRailBase.EnumRailDirection railBase = ((BlockRailBase) block.getBlock()).getRailDirection(minecart.worldObj, new BlockPos(xf, yf, zf), block, minecart); + y = yf; + + if (railBase.isAscending()) y = (double) (yf + 1); + + int[][] transformed = getMatrix()[railBase.getMetadata()]; + double dx = (double) (transformed[1][0] - transformed[0][0]); + double dz = (double) (transformed[1][2] - transformed[0][2]); + double len = Math.sqrt(dx * dx + dz * dz); + dx = dx / len; + dz = dz / len; + x = x + dx * offset; + z = z + dz * offset; + + if (transformed[0][1] != 0 && MathHelper.floor_double(x) - xf == transformed[0][0] && MathHelper.floor_double(z) - zf == transformed[0][2]) { + y += (double) transformed[0][1]; + } else if (transformed[1][1] != 0 && MathHelper.floor_double(x) - xf == transformed[1][0] && MathHelper.floor_double(z) - zf == transformed[1][2]) { + y += (double) transformed[1][1]; + } + + return minecart.getPos(x, y, z); + } else { + return null; + } + } + +} diff --git a/src/main/java/org/squiddev/plethora/gameplay/modules/ItemModule.java b/src/main/java/org/squiddev/plethora/gameplay/modules/ItemModule.java index 85e1ad0b..9e504b8d 100644 --- a/src/main/java/org/squiddev/plethora/gameplay/modules/ItemModule.java +++ b/src/main/java/org/squiddev/plethora/gameplay/modules/ItemModule.java @@ -7,6 +7,7 @@ import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.init.Blocks; import net.minecraft.init.Items; import net.minecraft.item.EnumAction; @@ -479,5 +480,9 @@ public static void launch(Entity entity, float yaw, float pitch, float power) { entity.fallDistance *= entity.motionY / TERMINAL_VELOCITY; } } + + if (ConfigGameplay.Kinetic.launchFloatReset && entity instanceof EntityPlayerMP) { + ((EntityPlayerMP) entity).connection.floatingTickCount = 0; + } } } diff --git a/src/main/java/org/squiddev/plethora/integration/cctweaks/IntegrationCCTweaks.java b/src/main/java/org/squiddev/plethora/integration/cctweaks/IntegrationCCTweaks.java index 4bfc8a30..7733c7e1 100644 --- a/src/main/java/org/squiddev/plethora/integration/cctweaks/IntegrationCCTweaks.java +++ b/src/main/java/org/squiddev/plethora/integration/cctweaks/IntegrationCCTweaks.java @@ -3,12 +3,16 @@ import net.minecraft.block.Block; import net.minecraft.item.Item; import net.minecraft.item.ItemBlock; +import net.minecraftforge.client.event.ModelBakeEvent; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.event.AttachCapabilitiesEvent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; import org.squiddev.cctweaks.CCTweaks; import org.squiddev.cctweaks.core.registry.Registry; import org.squiddev.plethora.core.PlethoraCore; +import org.squiddev.plethora.gameplay.client.RenderHelpers; import org.squiddev.plethora.utils.Helpers; public class IntegrationCCTweaks { @@ -30,4 +34,10 @@ public void attachCapabilities(AttachCapabilitiesEvent.Item event) { } } } + + @SubscribeEvent + @SideOnly(Side.CLIENT) + public void onModelBakeEvent(ModelBakeEvent event) { + RenderHelpers.loadModel(event, "cctweaks", "wireless_bridge_small"); + } } diff --git a/src/main/java/org/squiddev/plethora/integration/cctweaks/PeripheralHandlerWirelessBridge.java b/src/main/java/org/squiddev/plethora/integration/cctweaks/PeripheralHandlerWirelessBridge.java index 689c6829..e0046081 100644 --- a/src/main/java/org/squiddev/plethora/integration/cctweaks/PeripheralHandlerWirelessBridge.java +++ b/src/main/java/org/squiddev/plethora/integration/cctweaks/PeripheralHandlerWirelessBridge.java @@ -4,6 +4,10 @@ import dan200.computercraft.api.lua.LuaException; import dan200.computercraft.api.peripheral.IComputerAccess; import dan200.computercraft.api.peripheral.IPeripheral; +import net.minecraft.client.renderer.block.model.IBakedModel; +import net.minecraft.client.renderer.block.model.ModelManager; +import net.minecraft.client.renderer.block.model.ModelResourceLocation; +import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; @@ -17,23 +21,33 @@ import net.minecraft.world.World; import net.minecraftforge.common.capabilities.Capability; import net.minecraftforge.common.capabilities.ICapabilityProvider; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; +import org.apache.commons.lang3.tuple.Pair; import org.squiddev.cctweaks.api.IDataCard; import org.squiddev.cctweaks.api.IWorldPosition; import org.squiddev.cctweaks.core.network.bridge.NetworkBindingWithModem; import org.squiddev.cctweaks.core.network.modem.BasicModemPeripheral; import org.squiddev.plethora.api.Constants; import org.squiddev.plethora.api.IPeripheralHandler; +import org.squiddev.plethora.api.minecart.IMinecartAccess; +import org.squiddev.plethora.api.minecart.IMinecartUpgradeHandler; +import org.squiddev.plethora.gameplay.client.RenderHelpers; import javax.annotation.Nonnull; import javax.annotation.Nullable; +import javax.vecmath.Matrix4f; -public class PeripheralHandlerWirelessBridge implements IPeripheralHandler, IWorldPosition, ICapabilityProvider { +public class PeripheralHandlerWirelessBridge implements IPeripheralHandler, IMinecartUpgradeHandler, IWorldPosition, ICapabilityProvider { private final ItemStack stack; private World world; private BlockPos pos; - private EntityLivingBase entity; + private Entity entity; private PocketBinding binding; + @SideOnly(Side.CLIENT) + private ModelResourceLocation model; + public PeripheralHandlerWirelessBridge(ItemStack stack) { this.stack = stack; } @@ -47,6 +61,10 @@ public IPeripheral getPeripheral() { @Override public void update(@Nonnull World world, @Nonnull Vec3d position, @Nullable EntityLivingBase entity) { + update(world, position, (Entity) entity); + } + + private void update(@Nonnull World world, @Nonnull Vec3d position, @Nullable Entity entity) { this.world = world; this.pos = new BlockPos(position); this.entity = entity; @@ -67,13 +85,41 @@ public BlockPos getPosition() { @Override public boolean hasCapability(Capability capability, EnumFacing enumFacing) { - return capability == Constants.PERIPHERAL_HANDLER_CAPABILITY && stack.getItemDamage() == 0; + if (capability == Constants.PERIPHERAL_HANDLER_CAPABILITY) return stack.getItemDamage() == 0; + if (capability == Constants.MINECART_UPGRADE_HANDLER_CAPABILITY) return stack.getItemDamage() == 0; + return false; } @Override @SuppressWarnings("unchecked") public T getCapability(Capability capability, EnumFacing enumFacing) { - return capability == Constants.PERIPHERAL_HANDLER_CAPABILITY && stack.getItemDamage() == 0 ? (T) this : null; + if (capability == Constants.PERIPHERAL_HANDLER_CAPABILITY) { + return stack.getItemDamage() == 0 ? (T) this : null; + } + if (capability == Constants.MINECART_UPGRADE_HANDLER_CAPABILITY) { + return stack.getItemDamage() == 0 ? (T) this : null; + } + return null; + } + + @Nonnull + @Override + public Pair getModel(@Nonnull IMinecartAccess access) { + if (model == null) model = new ModelResourceLocation("cctweaks:wireless_bridge_small", "inventory"); + + ModelManager modelManager = RenderHelpers.getMesher().getModelManager(); + return Pair.of(modelManager.getModel(model), RenderHelpers.getIdentity()); + } + + @Override + public void update(@Nonnull IMinecartAccess minecart, @Nonnull IPeripheral peripheral) { + update(minecart.getMinecart().getEntityWorld(), minecart.getMinecart().getPositionVector(), minecart.getMinecart()); + } + + @Nullable + @Override + public IPeripheral create(@Nonnull IMinecartAccess minecart) { + return getPeripheral(); } private class PocketBinding extends NetworkBindingWithModem { @@ -181,8 +227,8 @@ public Object[] callMethod(IComputerAccess computer, ILuaContext context, int me ItemStack stack = inventory.getStackInSlot((i + held) % size); if (loadFromCard(stack)) return new Object[]{true}; } - } else { - ItemStack stack = entity.getHeldItem(EnumHand.MAIN_HAND); + } else if (entity instanceof EntityLivingBase) { + ItemStack stack = ((EntityLivingBase) entity).getHeldItem(EnumHand.MAIN_HAND); if (loadFromCard(stack)) return new Object[]{true}; } @@ -203,8 +249,8 @@ public Object[] callMethod(IComputerAccess computer, ILuaContext context, int me return new Object[]{true}; } } - } else { - ItemStack stack = entity.getHeldItem(EnumHand.MAIN_HAND); + } else if (entity instanceof EntityLivingBase) { + ItemStack stack = ((EntityLivingBase) entity).getHeldItem(EnumHand.MAIN_HAND); if (stack != null && stack.getItem() instanceof IDataCard) { IDataCard card = (IDataCard) stack.getItem(); PocketBinding.this.save(stack, card); diff --git a/src/main/java/org/squiddev/plethora/integration/computercraft/IntegrationComputerCraft.java b/src/main/java/org/squiddev/plethora/integration/computercraft/IntegrationComputerCraft.java index b6c3093f..68f3437e 100644 --- a/src/main/java/org/squiddev/plethora/integration/computercraft/IntegrationComputerCraft.java +++ b/src/main/java/org/squiddev/plethora/integration/computercraft/IntegrationComputerCraft.java @@ -6,7 +6,6 @@ import net.minecraft.client.renderer.vertex.DefaultVertexFormats; import net.minecraft.item.ItemStack; import net.minecraft.util.EnumFacing; -import net.minecraft.util.ResourceLocation; import net.minecraftforge.client.event.ModelBakeEvent; import net.minecraftforge.client.model.IModel; import net.minecraftforge.client.model.ModelLoader; @@ -16,10 +15,13 @@ import net.minecraftforge.common.capabilities.ICapabilityProvider; import net.minecraftforge.event.AttachCapabilitiesEvent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; import org.squiddev.plethora.api.Constants; import org.squiddev.plethora.api.IPeripheralHandler; import org.squiddev.plethora.api.minecart.IMinecartUpgradeHandler; import org.squiddev.plethora.core.PlethoraCore; +import org.squiddev.plethora.gameplay.client.RenderHelpers; import org.squiddev.plethora.utils.Helpers; import static org.squiddev.plethora.integration.computercraft.WirelessModemPeripheralBase.MinecartUpgradeHandler; @@ -47,17 +49,12 @@ public void attachCapabilities(AttachCapabilitiesEvent.Item event) { } @SubscribeEvent + @SideOnly(Side.CLIENT) public void onModelBakeEvent(ModelBakeEvent event) { - loadModel(event, "wireless_modem_off"); - loadModel(event, "wireless_modem_on"); - loadModel(event, "advanced_modem_off"); - loadModel(event, "advanced_modem_on"); - } - - private void loadModel(ModelBakeEvent event, String name) { - IModel model = ModelLoaderRegistry.getModelOrMissing(new ResourceLocation("computercraft", "block/" + name)); - IBakedModel bakedModel = model.bake(model.getDefaultState(), DefaultVertexFormats.ITEM, ModelLoader.defaultTextureGetter()); - event.getModelRegistry().putObject(new ModelResourceLocation("computercraft:" + name, "inventory"), bakedModel); + RenderHelpers.loadModel(event, "computercraft", "wireless_modem_off"); + RenderHelpers.loadModel(event, "computercraft", "wireless_modem_on"); + RenderHelpers.loadModel(event, "computercraft", "advanced_modem_off"); + RenderHelpers.loadModel(event, "computercraft", "advanced_modem_on"); } private static final class PeripheralCapabilityProvider implements ICapabilityProvider { diff --git a/src/main/resources/META-INF/Plethora_at.cfg b/src/main/resources/META-INF/Plethora_at.cfg index fae6a8e4..a5a05450 100644 --- a/src/main/resources/META-INF/Plethora_at.cfg +++ b/src/main/resources/META-INF/Plethora_at.cfg @@ -8,3 +8,6 @@ public net.minecraft.entity.monster.EntityEnderman func_70825_j(DDD)Z # teleport # Fake player # public net.minecraft.entity.player.EntityPlayer field_71074_e # itemInUse public net.minecraft.server.management.PlayerInteractionManager field_73094_o # durabilityRemainingOnBlock + +# Player flying +public net.minecraft.network.NetHandlerPlayServer field_147365_f # floatingTickCount diff --git a/src/main/resources/assets/plethora/lang/en_US.lang b/src/main/resources/assets/plethora/lang/en_US.lang index 480a648d..6199c579 100644 --- a/src/main/resources/assets/plethora/lang/en_US.lang +++ b/src/main/resources/assets/plethora/lang/en_US.lang @@ -104,6 +104,7 @@ gui.config.plethora.kinetic.launchCost=Launch cost gui.config.plethora.kinetic.launchYScale=Launch Y scale gui.config.plethora.kinetic.launchElytraScale=Launch Elytra scale gui.config.plethora.kinetic.launchFallReset=Launch fall-distance reset +gui.config.plethora.kinetic.launchFloatReset=Launch floating reset gui.config.plethora.kinetic.walkRange=Maximum walk range gui.config.plethora.kinetic.walkSpeed=Maximum walk speed gui.config.plethora.kinetic.walkCost=Walk cost