Added multipart gears and basic gear logic
This commit is contained in:
parent
5cdf1602bb
commit
2b0094ae6b
9 changed files with 375 additions and 114 deletions
|
@ -45,8 +45,14 @@ public class TileGenerator extends TileElectrical implements IMechanical
|
|||
}
|
||||
|
||||
@Override
|
||||
public void setKineticEnergy(long energy)
|
||||
public long getTorque()
|
||||
{
|
||||
this.power = energy;
|
||||
return this.power;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTorque(long torque)
|
||||
{
|
||||
this.power = torque;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -46,6 +46,7 @@ public class PartTransformer extends JCuboidPart implements JNormalOcclusion, TF
|
|||
oBoxes[s][1] = oBoxes[0][1].copy().apply(t);
|
||||
}
|
||||
}
|
||||
|
||||
/** Side of the block this is placed on */
|
||||
public ForgeDirection placementSide;
|
||||
/** Direction this block faces */
|
||||
|
@ -79,6 +80,12 @@ public class PartTransformer extends JCuboidPart implements JNormalOcclusion, TF
|
|||
return this.stepUp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean doesTick()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSlotMask()
|
||||
{
|
||||
|
|
|
@ -16,8 +16,7 @@ import resonantinduction.mechanical.fluid.pump.TileGrate;
|
|||
import resonantinduction.mechanical.fluid.pump.TilePump;
|
||||
import resonantinduction.mechanical.fluid.tank.BlockTank;
|
||||
import resonantinduction.mechanical.fluid.tank.TileTank;
|
||||
import resonantinduction.mechanical.gear.BlockGear;
|
||||
import resonantinduction.mechanical.gear.TileGear;
|
||||
import resonantinduction.mechanical.gear.ItemGear;
|
||||
import resonantinduction.mechanical.item.ItemPipeGauge;
|
||||
import resonantinduction.mechanical.logistic.BlockDetector;
|
||||
import resonantinduction.mechanical.logistic.BlockManipulator;
|
||||
|
@ -37,74 +36,77 @@ import cpw.mods.fml.common.event.FMLPreInitializationEvent;
|
|||
import cpw.mods.fml.common.network.NetworkMod;
|
||||
import cpw.mods.fml.common.network.NetworkRegistry;
|
||||
|
||||
/** Resonant Induction Archaic Module
|
||||
/**
|
||||
* Resonant Induction Archaic Module
|
||||
*
|
||||
* @author DarkCow, Calclavia */
|
||||
* @author DarkCow, Calclavia
|
||||
*/
|
||||
@Mod(modid = Mechanical.ID, name = Mechanical.NAME, version = Reference.VERSION, dependencies = "required-after:" + ResonantInduction.ID)
|
||||
@NetworkMod(channels = Reference.CHANNEL, clientSideRequired = true, serverSideRequired = false, packetHandler = PacketHandler.class)
|
||||
public class Mechanical
|
||||
{
|
||||
/** Mod Information */
|
||||
public static final String ID = "ResonantInduction|Mechanical";
|
||||
public static final String NAME = Reference.NAME + " Mechanical";
|
||||
/** Mod Information */
|
||||
public static final String ID = "ResonantInduction|Mechanical";
|
||||
public static final String NAME = Reference.NAME + " Mechanical";
|
||||
|
||||
@Instance(ID)
|
||||
public static Mechanical INSTANCE;
|
||||
@Instance(ID)
|
||||
public static Mechanical INSTANCE;
|
||||
|
||||
@SidedProxy(clientSide = "resonantinduction.mechanical.ClientProxy", serverSide = "resonantinduction.mechanical.CommonProxy")
|
||||
public static CommonProxy proxy;
|
||||
@SidedProxy(clientSide = "resonantinduction.mechanical.ClientProxy", serverSide = "resonantinduction.mechanical.CommonProxy")
|
||||
public static CommonProxy proxy;
|
||||
|
||||
@Mod.Metadata(ID)
|
||||
public static ModMetadata metadata;
|
||||
@Mod.Metadata(ID)
|
||||
public static ModMetadata metadata;
|
||||
|
||||
public static final ContentRegistry contentRegistry = new ContentRegistry(Settings.CONFIGURATION, ID);
|
||||
public static final ContentRegistry contentRegistry = new ContentRegistry(Settings.CONFIGURATION, ID);
|
||||
|
||||
// Energy
|
||||
public static Block blockGear;
|
||||
public static Block blockGearShaft;
|
||||
// Energy
|
||||
public static Item itemGear;
|
||||
public static Block itemGearShaft;
|
||||
|
||||
// Transport
|
||||
public static Block blockConveyorBelt;
|
||||
public static Block blockManipulator;
|
||||
public static Block blockDetector;
|
||||
public static Block blockRejector;
|
||||
// Transport
|
||||
public static Block blockConveyorBelt;
|
||||
public static Block blockManipulator;
|
||||
public static Block blockDetector;
|
||||
public static Block blockRejector;
|
||||
|
||||
// Fluids
|
||||
public static Block blockTank;
|
||||
public static Block blockPipe;
|
||||
public static Block blockReleaseValve;
|
||||
public static Block blockGrate;
|
||||
public static Block blockPump;
|
||||
// Fluids
|
||||
public static Block blockTank;
|
||||
public static Block blockPipe;
|
||||
public static Block blockReleaseValve;
|
||||
public static Block blockGrate;
|
||||
public static Block blockPump;
|
||||
|
||||
public static Item itemPipeGuage;
|
||||
public static Item itemPipeGuage;
|
||||
|
||||
@EventHandler
|
||||
public void preInit(FMLPreInitializationEvent evt)
|
||||
{
|
||||
Settings.load();
|
||||
NetworkRegistry.instance().registerGuiHandler(this, proxy);
|
||||
blockGear = contentRegistry.createTile(BlockGear.class, TileGear.class);
|
||||
//blockGearShaft = contentRegistry.createTile(BlockRejector.class, TileRejector.class);
|
||||
@EventHandler
|
||||
public void preInit(FMLPreInitializationEvent evt)
|
||||
{
|
||||
Settings.load();
|
||||
NetworkRegistry.instance().registerGuiHandler(this, proxy);
|
||||
itemGear = contentRegistry.createItem(ItemGear.class);
|
||||
|
||||
blockConveyorBelt = contentRegistry.createTile(BlockConveyorBelt.class, TileConveyorBelt.class);
|
||||
blockManipulator = contentRegistry.createTile(BlockManipulator.class, TileManipulator.class);
|
||||
blockDetector = contentRegistry.createTile(BlockDetector.class, TileDetector.class);
|
||||
blockRejector = contentRegistry.createTile(BlockRejector.class, TileRejector.class);
|
||||
blockConveyorBelt = contentRegistry.createTile(BlockConveyorBelt.class, TileConveyorBelt.class);
|
||||
blockManipulator = contentRegistry.createTile(BlockManipulator.class, TileManipulator.class);
|
||||
blockDetector = contentRegistry.createTile(BlockDetector.class, TileDetector.class);
|
||||
blockRejector = contentRegistry.createTile(BlockRejector.class, TileRejector.class);
|
||||
|
||||
blockTank = contentRegistry.createBlock(BlockTank.class, ItemBlockFluidContainer.class, TileTank.class);
|
||||
blockPipe = contentRegistry.createBlock(BlockPipe.class, ItemBlockFluidContainer.class, TilePipe.class);
|
||||
blockGrate = contentRegistry.createTile(BlockGrate.class, TileGrate.class);
|
||||
blockPump = contentRegistry.createTile(BlockPump.class, TilePump.class);
|
||||
blockTank = contentRegistry.createBlock(BlockTank.class, ItemBlockFluidContainer.class, TileTank.class);
|
||||
blockPipe = contentRegistry.createBlock(BlockPipe.class, ItemBlockFluidContainer.class, TilePipe.class);
|
||||
blockGrate = contentRegistry.createTile(BlockGrate.class, TileGrate.class);
|
||||
blockPump = contentRegistry.createTile(BlockPump.class, TilePump.class);
|
||||
|
||||
itemPipeGuage = contentRegistry.createItem("PipeGauge", ItemPipeGauge.class);
|
||||
proxy.preInit();
|
||||
Settings.save();
|
||||
}
|
||||
itemPipeGuage = contentRegistry.createItem(ItemPipeGauge.class);
|
||||
|
||||
@EventHandler
|
||||
public void init(FMLInitializationEvent evt)
|
||||
{
|
||||
Settings.setModMetadata(metadata, ID, NAME);
|
||||
proxy.init();
|
||||
}
|
||||
proxy.preInit();
|
||||
Settings.save();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void init(FMLInitializationEvent evt)
|
||||
{
|
||||
MultipartMechanical.INSTANCE = new MultipartMechanical();
|
||||
Settings.setModMetadata(metadata, ID, NAME);
|
||||
proxy.init();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
package resonantinduction.mechanical;
|
||||
|
||||
import resonantinduction.mechanical.gear.PartGear;
|
||||
import codechicken.multipart.MultiPartRegistry;
|
||||
import codechicken.multipart.MultiPartRegistry.IPartFactory;
|
||||
import codechicken.multipart.TMultiPart;
|
||||
|
||||
public class MultipartMechanical implements IPartFactory
|
||||
{
|
||||
public static MultipartMechanical INSTANCE;
|
||||
|
||||
public static final String[] PART_TYPES = { "resonant_induction_gear" };
|
||||
|
||||
public MultipartMechanical()
|
||||
{
|
||||
MultiPartRegistry.registerParts(this, PART_TYPES);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TMultiPart createPart(String name, boolean client)
|
||||
{
|
||||
switch (name)
|
||||
{
|
||||
case "resonant_induction_gear":
|
||||
return new PartGear();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -1,45 +0,0 @@
|
|||
package resonantinduction.mechanical.gear;
|
||||
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
import resonantinduction.core.prefab.block.BlockRI;
|
||||
import resonantinduction.mechanical.render.MechanicalBlockRenderingHandler;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
public class BlockGear extends BlockRI
|
||||
{
|
||||
public BlockGear()
|
||||
{
|
||||
super("gear", Material.wood);
|
||||
this.setHardness(1f);
|
||||
this.setResistance(1f);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOpaqueCube()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public boolean renderAsNormalBlock()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public int getRenderType()
|
||||
{
|
||||
return MechanicalBlockRenderingHandler.ID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity createNewTileEntity(World var1)
|
||||
{
|
||||
return new TileGear();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
package resonantinduction.mechanical.gear;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.Icon;
|
||||
import net.minecraft.world.World;
|
||||
import resonantinduction.core.Settings;
|
||||
import resonantinduction.core.prefab.part.ItemMultipartBase;
|
||||
import resonantinduction.electrical.wire.EnumWireMaterial;
|
||||
import codechicken.lib.vec.BlockCoord;
|
||||
import codechicken.lib.vec.Vector3;
|
||||
import codechicken.multipart.MultiPartRegistry;
|
||||
import codechicken.multipart.TMultiPart;
|
||||
|
||||
public class ItemGear extends ItemMultipartBase
|
||||
{
|
||||
public ItemGear()
|
||||
{
|
||||
super("gear", Settings.getNextItemID());
|
||||
}
|
||||
|
||||
@Override
|
||||
public TMultiPart newPart(ItemStack itemStack, EntityPlayer player, World world, BlockCoord pos, int side, Vector3 hit)
|
||||
{
|
||||
PartGear part = (PartGear) MultiPartRegistry.createPart("resonant_induction_gear", false);
|
||||
|
||||
if (part != null)
|
||||
{
|
||||
part.preparePlacement(side, itemStack.getItemDamage());
|
||||
}
|
||||
|
||||
return part;
|
||||
}
|
||||
}
|
235
src/main/java/resonantinduction/mechanical/gear/PartGear.java
Normal file
235
src/main/java/resonantinduction/mechanical/gear/PartGear.java
Normal file
|
@ -0,0 +1,235 @@
|
|||
package resonantinduction.mechanical.gear;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.MovingObjectPosition;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import resonantinduction.mechanical.Mechanical;
|
||||
import resonantinduction.mechanical.network.IMechanical;
|
||||
import codechicken.lib.data.MCDataInput;
|
||||
import codechicken.lib.data.MCDataOutput;
|
||||
import codechicken.lib.vec.Cuboid6;
|
||||
import codechicken.lib.vec.Rotation;
|
||||
import codechicken.lib.vec.Transformation;
|
||||
import codechicken.lib.vec.Vector3;
|
||||
import codechicken.microblock.FaceMicroClass;
|
||||
import codechicken.multipart.JCuboidPart;
|
||||
import codechicken.multipart.JNormalOcclusion;
|
||||
import codechicken.multipart.TFacePart;
|
||||
import codechicken.multipart.TMultiPart;
|
||||
import codechicken.multipart.TileMultipart;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
public class PartGear extends JCuboidPart implements JNormalOcclusion, TFacePart, IMechanical
|
||||
{
|
||||
public static Cuboid6[][] oBoxes = new Cuboid6[6][2];
|
||||
|
||||
static
|
||||
{
|
||||
oBoxes[0][0] = new Cuboid6(1 / 8D, 0, 0, 7 / 8D, 1 / 8D, 1);
|
||||
oBoxes[0][1] = new Cuboid6(0, 0, 1 / 8D, 1, 1 / 8D, 7 / 8D);
|
||||
for (int s = 1; s < 6; s++)
|
||||
{
|
||||
Transformation t = Rotation.sideRotations[s].at(Vector3.center);
|
||||
oBoxes[s][0] = oBoxes[0][0].copy().apply(t);
|
||||
oBoxes[s][1] = oBoxes[0][1].copy().apply(t);
|
||||
}
|
||||
}
|
||||
/** Side of the block this is placed on */
|
||||
private ForgeDirection placementSide;
|
||||
|
||||
/** Positive torque means it is spinning clockwise */
|
||||
private long torque = 0;
|
||||
|
||||
public void preparePlacement(int side, int itemDamage)
|
||||
{
|
||||
this.placementSide = ForgeDirection.getOrientation((byte) (side ^ 1));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update()
|
||||
{
|
||||
// TODO: Should we average the torque?
|
||||
/**
|
||||
* Look for gears that are back-to-back with this gear. Equate torque.
|
||||
*/
|
||||
universalelectricity.api.vector.Vector3 vec = new universalelectricity.api.vector.Vector3(tile()).modifyPositionFromSide(placementSide);
|
||||
|
||||
TileEntity tile = vec.getTileEntity(world());
|
||||
|
||||
if (tile instanceof TileMultipart)
|
||||
{
|
||||
TMultiPart part = ((TileMultipart) tile).partMap(this.placementSide.getOpposite().ordinal());
|
||||
|
||||
if (part instanceof PartGear)
|
||||
{
|
||||
torque = (torque + ((PartGear) part).torque) / 2;
|
||||
((PartGear) part).torque = torque;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Look for gears outside this block space, the relative UP, DOWN, LEFT, RIGHT
|
||||
*/
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
ForgeDirection checkDir = ForgeDirection.getOrientation(Rotation.rotateSide(this.placementSide.ordinal(), i));
|
||||
universalelectricity.api.vector.Vector3 checkVec = new universalelectricity.api.vector.Vector3(tile()).modifyPositionFromSide(checkDir);
|
||||
|
||||
TileEntity checkTile = checkVec.getTileEntity(world());
|
||||
|
||||
if (checkTile instanceof TileMultipart)
|
||||
{
|
||||
TMultiPart neighbor = ((TileMultipart) checkTile).partMap(this.placementSide.ordinal());
|
||||
|
||||
if (neighbor instanceof PartGear)
|
||||
{
|
||||
torque = (torque - ((PartGear) neighbor).torque) / 2;
|
||||
((PartGear) neighbor).torque = -torque;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Look for gears that are internal and adjacent to this gear. (The 2 sides)
|
||||
*/
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
// TODO: Make it work with UP-DOWN
|
||||
if (i < 2)
|
||||
{
|
||||
TMultiPart neighbor = tile().partMap(this.placementSide.getRotation(ForgeDirection.getOrientation(i)).ordinal());
|
||||
|
||||
if (neighbor instanceof PartGear)
|
||||
{
|
||||
torque = (torque - ((PartGear) neighbor).torque) / 2;
|
||||
((PartGear) neighbor).torque = -torque;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean activate(EntityPlayer player, MovingObjectPosition hit, ItemStack item)
|
||||
{
|
||||
System.out.println("Torque" + this.torque);
|
||||
|
||||
if (player.isSneaking())
|
||||
{
|
||||
this.torque += 10;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Packet Code.
|
||||
*/
|
||||
@Override
|
||||
public void readDesc(MCDataInput packet)
|
||||
{
|
||||
this.placementSide = ForgeDirection.getOrientation(packet.readByte());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeDesc(MCDataOutput packet)
|
||||
{
|
||||
packet.writeByte(this.placementSide.ordinal());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSlotMask()
|
||||
{
|
||||
return 1 << this.placementSide.ordinal();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Cuboid6 getBounds()
|
||||
{
|
||||
return FaceMicroClass.aBounds()[0x10 | this.placementSide.ordinal()];
|
||||
}
|
||||
|
||||
@Override
|
||||
public int redstoneConductionMap()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean solid(int arg0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<Cuboid6> getOcclusionBoxes()
|
||||
{
|
||||
return Arrays.asList(oBoxes[this.placementSide.ordinal()]);
|
||||
}
|
||||
|
||||
protected ItemStack getItem()
|
||||
{
|
||||
return new ItemStack(Mechanical.itemGear);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<ItemStack> getDrops()
|
||||
{
|
||||
List<ItemStack> drops = new ArrayList<ItemStack>();
|
||||
drops.add(getItem());
|
||||
return drops;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack pickItem(MovingObjectPosition hit)
|
||||
{
|
||||
return getItem();
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void renderDynamic(Vector3 pos, float frame, int pass)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load(NBTTagCompound nbt)
|
||||
{
|
||||
super.load(nbt);
|
||||
this.placementSide = ForgeDirection.getOrientation(nbt.getByte("side"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save(NBTTagCompound nbt)
|
||||
{
|
||||
super.save(nbt);
|
||||
nbt.setByte("side", (byte) this.placementSide.ordinal());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getType()
|
||||
{
|
||||
return "resonant_induction_gear";
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getTorque()
|
||||
{
|
||||
return this.torque;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTorque(long torque)
|
||||
{
|
||||
this.torque = torque;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,12 +0,0 @@
|
|||
package resonantinduction.mechanical.gear;
|
||||
|
||||
import calclavia.lib.prefab.tile.TileAdvanced;
|
||||
|
||||
/**
|
||||
* @author Calclavia
|
||||
*
|
||||
*/
|
||||
public class TileGear extends TileAdvanced
|
||||
{
|
||||
|
||||
}
|
|
@ -1,10 +1,14 @@
|
|||
package resonantinduction.mechanical.network;
|
||||
|
||||
/**
|
||||
* For the mechanical network.
|
||||
*
|
||||
* @author Calclavia
|
||||
*
|
||||
*/
|
||||
public interface IMechanical
|
||||
{
|
||||
public void setKineticEnergy(long energy);
|
||||
public long getTorque();
|
||||
|
||||
public void setTorque(long torque);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue