Skip to content
This repository has been archived by the owner on Aug 26, 2021. It is now read-only.

Commit

Permalink
Merge branch 'minecraft-1.8.9' into minecraft-1.10.2
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/main/java/org/squiddev/plethora/gameplay/ConfigGameplay.java
#	src/main/java/org/squiddev/plethora/gameplay/client/RenderHelpers.java
#	src/main/java/org/squiddev/plethora/gameplay/minecart/EntityMinecartComputer.java
#	src/main/java/org/squiddev/plethora/integration/cctweaks/PeripheralHandlerWirelessBridge.java
#	src/main/java/org/squiddev/plethora/integration/computercraft/IntegrationComputerCraft.java
#	src/main/resources/META-INF/Plethora_at.cfg
  • Loading branch information
SquidDev committed Apr 7, 2017
2 parents 028fdfa + 85c0357 commit aea3667
Show file tree
Hide file tree
Showing 12 changed files with 180 additions and 29 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ processResources {

gradle.projectsEvaluated {
tasks.withType(JavaCompile) {
options.compilerArgs << "-Xlint" << "-Xlint:-rawtypes"
options.compilerArgs << "-Xlint" << "-Xlint:-rawtypes" << "-Xlint:-processing"
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -78,7 +77,7 @@ private Object getBlockInfo(World world, BlockPos pos) {
table.put("metadata", metadata);

Map<Object, Object> stateTable = Maps.newHashMap();
for (Map.Entry<IProperty<?>, ?> entry : block.getActualState(state, world, pos).getProperties().entrySet()) {
for (Map.Entry<IProperty<?>, ?> 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) {
Expand All @@ -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);
}
});
}
Expand All @@ -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};
Expand Down Expand Up @@ -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));
}
}
}
Expand All @@ -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");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
Expand All @@ -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;
Expand All @@ -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> T getCapability(Capability<T> 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<IBakedModel, Matrix4f> 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 {
Expand Down Expand Up @@ -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};
}

Expand All @@ -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);
Expand Down
Loading

0 comments on commit aea3667

Please sign in to comment.