mirror of
https://github.com/GTNewHorizons/EnderIO.git
synced 2026-11-23 21:49:58 +00:00
Add Immibis Microblocks support for conduits
This commit is contained in:
1 parent
712e1262ce
commit
9c315e7557
30 files changed
+1560
-19
No files matched your search
@@ -0,0 +1,27 @@
|
||||
package mods.immibis.core.api.multipart;
|
||||
|
||||
|
||||
/**
|
||||
* An object that allows extra parts to be added to multipart tiles.
|
||||
* For example, you can add covers to InfiniTubes transport conduits
|
||||
* because they use a MicroblockCoverSystem.
|
||||
*
|
||||
* This interface's existence is a bit unintuitive, but it seemed to "naturally fall out" of the design.
|
||||
*/
|
||||
public interface ICoverSystem extends IPartContainer {
|
||||
/**
|
||||
* Converts the block containing this cover system into
|
||||
* a block containing only parts from this cover system,
|
||||
* or to air if the cover system has no parts.
|
||||
*
|
||||
* Call it when, for example, all wires in a RedLogic wire block are destroyed,
|
||||
* to replace it with a microblock container block if there were any microblocks
|
||||
* in the wire block.
|
||||
*
|
||||
* TODO should this be called on the client, server or both?
|
||||
*
|
||||
* Note: For custom implementations, this should be capable of being called even after
|
||||
* the block and tile entity are removed (and should resurrect them)
|
||||
*/
|
||||
public void convertToContainerBlock();
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package mods.immibis.core.api.multipart;
|
||||
|
||||
|
||||
/** Multipart tiles can also implement IPartContainer4 if they have their own parts (as well as cover system parts) */
|
||||
public interface ICoverableTile {
|
||||
/**
|
||||
* Returns an ICoverSystem object, or null if this tile does not support a cover system
|
||||
* @see mods.immibis.core.api.multipart.ICoverSystem
|
||||
*/
|
||||
public ICoverSystem getCoverSystem();
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package mods.immibis.core.api.multipart;
|
||||
|
||||
import net.minecraft.client.renderer.RenderBlocks;
|
||||
|
||||
/**
|
||||
* If a Block class implements this, {@link IMultipartSystem#renderMultiparts(net.minecraft.world.IBlockAccess, int, int, int, net.minecraft.client.renderer.RenderBlocks)}
|
||||
* will automatically be called for that block type (after the normal block renderer).
|
||||
* This is implemented by a hooking {@link RenderBlocks#renderBlockByRenderType(net.minecraft.block.Block, int, int, int)}.
|
||||
*
|
||||
* (Instead of this, there used to be a transformer that would modify your getRenderType and use a wrapping ISBRH.
|
||||
* That was unreliable, and could have affected unrelated things like mob AI, and didn't work with Railcraft, so
|
||||
* it was dropped)
|
||||
*/
|
||||
public interface IMultipartRenderingBlockMarker {
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
package mods.immibis.core.api.multipart;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import net.minecraft.client.particle.EffectRenderer;
|
||||
import net.minecraft.client.renderer.RenderBlocks;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
import net.minecraft.util.MovingObjectPosition;
|
||||
import net.minecraft.util.Vec3;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
/**
|
||||
* Provides methods allowing blocks to implement microblock ("covering") support.
|
||||
* All of the methods in this class do nothing, but are overridden if Immibis Core is installed.
|
||||
*/
|
||||
public class IMultipartSystem {
|
||||
|
||||
/** Immibis Core sets this to an actual implementation during load time */
|
||||
public static @Nonnull IMultipartSystem instance = new IMultipartSystem();
|
||||
|
||||
/** Call this from addCollisionBoxesToList for cover-supporting blocks.
|
||||
* Returns true if the tile entity implements IPartContainer.
|
||||
*/
|
||||
public boolean hook_addCollisionBoxesToList(World world, int x, int y, int z, AxisAlignedBB mask, List<AxisAlignedBB> list, Entity entity) {return false;}
|
||||
|
||||
/** Call this from getPickBlock for cover-supporting blocks. If it returns a non-null value, then return that. */
|
||||
public ItemStack hook_getPickBlock(MovingObjectPosition trace, World world, int blockX, int blockY, int blockZ, EntityPlayer player) {return null;}
|
||||
|
||||
/** Call this from isSideSolid for cover-supporting blocks. If it returns true, then return true. */
|
||||
public boolean hook_isSideSolid(IBlockAccess world, int x, int y, int z, ForgeDirection side) {return false;}
|
||||
|
||||
/** Call this from addHitEffects for cover-supporting blocks. If it returns true, then return true without adding any custom effects. */
|
||||
@SideOnly(Side.CLIENT)
|
||||
public boolean hook_addHitEffects(World world, MovingObjectPosition trace, EffectRenderer effectRenderer) {return false;}
|
||||
|
||||
/** Call this from addDestroyEffects for cover-supporting blocks. If it returns true, then return true without adding any custom effects. */
|
||||
@SideOnly(Side.CLIENT)
|
||||
public boolean hook_addDestroyEffects(World world, int x, int y, int z, int meta, EffectRenderer effectRenderer) {return false;}
|
||||
|
||||
/** Call this from collisionRayTrace for cover-supporting blocks, before returning. Pass it the result you were going to return (even if that was null). */
|
||||
public MovingObjectPosition hook_collisionRayTrace(MovingObjectPosition normalResult, World world, int x, int y, int z, Vec3 src, Vec3 dst) {return normalResult;}
|
||||
|
||||
/** Call this from getDrops for cover-supporting blocks, before returning. Pass it the result you were going to return. */
|
||||
public ArrayList<ItemStack> hook_getDrops(List<ItemStack> drops, World world, int x, int y, int z, int metadata, int fortune) {return drops instanceof ArrayList<?> ? (ArrayList<ItemStack>)drops : new ArrayList<ItemStack>(drops);}
|
||||
|
||||
/** Call this from your renderer's renderWorldBlock for cover-supporting blocks, before returning.
|
||||
* If it returns true (indicating it rendered something), then return true.
|
||||
* (Render your custom stuff regardless of what this returns)
|
||||
*
|
||||
* If there is a tile entity implementing ICoverableTile with a non-null cover system, it will call renderPartContainer on that.
|
||||
* If there is a tile entity implementing IPartContainer, it will call renderPartContainer on that.
|
||||
*/
|
||||
@SideOnly(Side.CLIENT)
|
||||
public boolean renderMultiparts(IBlockAccess world, int x, int y, int z, RenderBlocks renderer) {return false;}
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
package mods.immibis.core.api.multipart;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.client.particle.EffectRenderer;
|
||||
import net.minecraft.client.renderer.RenderBlocks;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
import net.minecraft.util.MovingObjectPosition;
|
||||
import net.minecraft.util.Vec3;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
/**
|
||||
* Contains common methods from ICoverSystem and IMultipartTile.
|
||||
*/
|
||||
public interface IPartContainer {
|
||||
|
||||
/**
|
||||
* Gets the speed at which a player breaks a part.
|
||||
* See Block.getPlayerRelativeBlockHardness.
|
||||
* @param ply The player.
|
||||
* @param The part.
|
||||
* @return The speed.
|
||||
*/
|
||||
float getPlayerRelativePartHardness(EntityPlayer ply, int part);
|
||||
|
||||
/**
|
||||
* Called when the player middle-clicks on a part.
|
||||
* @param rayTrace The location under the player's crosshair.
|
||||
* @param part The part number they middle-clicked on.
|
||||
* @return The itemstack to pick.
|
||||
*/
|
||||
public ItemStack pickPart(MovingObjectPosition rayTrace, int part);
|
||||
|
||||
/**
|
||||
* Checks if a given face of this block is solid.
|
||||
* Used to determine the result of Block.isBlockSolidOnSide.
|
||||
*/
|
||||
public boolean isPartContainerSideSolid(ForgeDirection side);
|
||||
|
||||
/**
|
||||
* Called when a player finishes breaking a part.
|
||||
* @param ply The player breaking the part.
|
||||
* @param subhit The part being broken.
|
||||
* @param harvest Whether items/XP/etc should be dropped.
|
||||
*/
|
||||
public void removePartByPlayer(EntityPlayer ply, int part, boolean harvest);
|
||||
|
||||
/**
|
||||
* Returns the AABB of a part, in tile-local coordinates.
|
||||
* Currently used for drawing the selection box.
|
||||
* May return null, in which case no selection box is drawn.
|
||||
*
|
||||
* @param part The part ID to check.
|
||||
* @return The AABB of the part, or null.
|
||||
*/
|
||||
public AxisAlignedBB getPartAABBFromPool(int part);
|
||||
|
||||
/**
|
||||
* Renders all the parts.
|
||||
* @param render The render context.
|
||||
* @return True if anything was rendered.
|
||||
*/
|
||||
@SideOnly(Side.CLIENT)
|
||||
public boolean renderPartContainer(RenderBlocks render);
|
||||
|
||||
/**
|
||||
* Renders one part.
|
||||
* @param render The render context.
|
||||
* @param part The part number.
|
||||
* @return True if anything was rendered.
|
||||
*/
|
||||
@SideOnly(Side.CLIENT)
|
||||
public boolean renderPart(RenderBlocks render, int part);
|
||||
|
||||
/**
|
||||
* Creates particles when a part is destroyed.
|
||||
* If the part number is invalid, returns false.
|
||||
* Otherwise, creates particles if applicable, and returns true.
|
||||
*/
|
||||
@SideOnly(Side.CLIENT)
|
||||
public boolean addPartDestroyEffects(int part, EffectRenderer er);
|
||||
|
||||
/**
|
||||
* Returns true if the given player can currently harvest the given part (using their selected item)
|
||||
* @param player The player to check.
|
||||
* @param part The index of the part the player is trying to harvest.
|
||||
* @return True iff the player can harvest the part.
|
||||
*/
|
||||
public boolean canPlayerHarvestPart(EntityPlayer entityPlayer, int part);
|
||||
|
||||
/**
|
||||
* Adds the complete drops from this cover system to the given list.
|
||||
* Note that is not normally used when breaking microblocks.
|
||||
* @param drops The list to add the drops to.
|
||||
* @param fortune The fortune level involved.
|
||||
*/
|
||||
public void getPartContainerDrops(List<ItemStack> drops, int fortune);
|
||||
|
||||
/**
|
||||
* Creates particles when a part is punched.
|
||||
* Returns false if anything goes wrong, which indicates to use the default particle effect.
|
||||
* Otherwise, creates particles (if applicable), and returns true.
|
||||
*/
|
||||
@SideOnly(Side.CLIENT)
|
||||
public boolean addPartHitEffects(int part, int sideHit, EffectRenderer er);
|
||||
|
||||
/**
|
||||
* Finds the closest intercept of the given ray with parts in this container.
|
||||
* @param src The start of the ray, in world coordinates.
|
||||
* @param dst The end of the ray, in world coordinates.
|
||||
* @return A ray-trace result, or null if the ray does not intersect any parts.
|
||||
*/
|
||||
public MovingObjectPosition collisionRayTrace(Vec3 src, Vec3 dst);
|
||||
|
||||
/**
|
||||
* Returns all collision boxes that intersect the given mask, in world coordinates.
|
||||
* @param mask The mask AABB, in world coordinates.
|
||||
* @param list The list to add the returned boxes to.
|
||||
*
|
||||
* Used to implement Block.addCollisionBoxesToList.
|
||||
*/
|
||||
public void getCollidingBoundingBoxes(AxisAlignedBB mask, List<AxisAlignedBB> list, Entity entity);
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package mods.immibis.core.api.multipart;
|
||||
|
||||
import cpw.mods.fml.common.eventhandler.Cancelable;
|
||||
import cpw.mods.fml.common.eventhandler.Event;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
/**
|
||||
* Fired on the Forge event bus when a part finishes being broken.
|
||||
*
|
||||
* This is fired on both the client and server.
|
||||
*/
|
||||
@Cancelable
|
||||
public class PartBreakEvent extends Event {
|
||||
public final World world;
|
||||
public final PartCoordinates coords;
|
||||
public final EntityLivingBase player;
|
||||
|
||||
public PartBreakEvent(World world, PartCoordinates coords, EntityLivingBase player) {
|
||||
this.world = world;
|
||||
this.coords = coords;
|
||||
this.player = player;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package mods.immibis.core.api.multipart;
|
||||
|
||||
public final class PartCoordinates {
|
||||
public final int x, y, z, part;
|
||||
public final boolean isCoverSystemPart;
|
||||
public PartCoordinates(int x, int y, int z, int part, boolean isCoverSystemPart) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
this.part = part;
|
||||
this.isCoverSystemPart = isCoverSystemPart;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return ((x * 257 + y) * 257 + z) * 257 + part;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if(obj == null)
|
||||
return false;
|
||||
try {
|
||||
PartCoordinates o = (PartCoordinates)obj;
|
||||
return x == o.x && y == o.y && z == o.z && part == o.part && isCoverSystemPart == o.isCoverSystemPart;
|
||||
} catch(ClassCastException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "[" + x + "," + y + "," + z + ":" + part + "]";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
package mods.immibis.core.api.multipart.util;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import mods.immibis.core.api.multipart.IMultipartRenderingBlockMarker;
|
||||
import mods.immibis.core.api.multipart.IMultipartSystem;
|
||||
import net.minecraft.block.BlockContainer;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.client.particle.EffectRenderer;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
import net.minecraft.util.MovingObjectPosition;
|
||||
import net.minecraft.util.Vec3;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
|
||||
public abstract class BlockMultipartBase extends BlockContainer implements IMultipartRenderingBlockMarker {
|
||||
|
||||
protected BlockMultipartBase(Material mat) {
|
||||
super(mat);
|
||||
|
||||
setHardness(1); // the block hardness must not be zero.
|
||||
// if using IPartContainer tiles, the block hardness should be irrelevant, but still can't be zero.
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Override public final boolean isOpaqueCube() {return false;}
|
||||
@Override public final boolean renderAsNormalBlock() {return false;}
|
||||
@Override public boolean shouldSideBeRendered(IBlockAccess par1iBlockAccess, int par2, int par3, int par4, int par5) {return true;}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public ItemStack getPickBlock(MovingObjectPosition target, World world, int x, int y, int z, EntityPlayer player) {
|
||||
ItemStack coverPick = IMultipartSystem.instance.hook_getPickBlock(target, world, x, y, z, player);
|
||||
if(coverPick != null)
|
||||
return coverPick;
|
||||
|
||||
return super.getPickBlock(target, world, x, y, z, player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSideSolid(IBlockAccess world, int x, int y, int z, ForgeDirection side) {
|
||||
if(IMultipartSystem.instance.hook_isSideSolid(world, x, y, z, side))
|
||||
return true;
|
||||
|
||||
return super.isSideSolid(world, x, y, z, side);
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public boolean addDestroyEffects(World world, int x, int y, int z, int meta, EffectRenderer effectRenderer) {
|
||||
if(IMultipartSystem.instance.hook_addDestroyEffects(world, x, y, z, meta, effectRenderer))
|
||||
return true;
|
||||
|
||||
return super.addDestroyEffects(world, x, y, z, meta, effectRenderer);
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public boolean addHitEffects(World worldObj, MovingObjectPosition target, EffectRenderer effectRenderer) {
|
||||
if(IMultipartSystem.instance.hook_addHitEffects(worldObj, target, effectRenderer))
|
||||
return true;
|
||||
|
||||
return super.addHitEffects(worldObj, target, effectRenderer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MovingObjectPosition collisionRayTrace(World world, int x, int y, int z, Vec3 src, Vec3 dst) {
|
||||
return IMultipartSystem.instance.hook_collisionRayTrace(super.collisionRayTrace(world, x, y, z, src, dst), world, x, y, z, src, dst);
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
@Override
|
||||
public void addCollisionBoxesToList(World world, int x, int y, int z, AxisAlignedBB mask, List list, Entity entity) {
|
||||
// Note: if you're implementing this yourself (instead of extending this class) you don't need to check the
|
||||
// return value of hook_addCollisionBlocksToList.
|
||||
// The check is to allow BlockMultipartBase to work with both multipart and normal blocks.
|
||||
if(!IMultipartSystem.instance.hook_addCollisionBoxesToList(world, x, y, z, mask, list, entity))
|
||||
super.addCollisionBoxesToList(world, x, y, z, mask, list, entity);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ArrayList<ItemStack> getDrops(World world, int x, int y, int z, int metadata, int fortune) {
|
||||
return IMultipartSystem.instance.hook_getDrops(super.getDrops(world, x, y, z, metadata, fortune), world, x, y, z, metadata, fortune);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package mods.immibis.core.api.util;
|
||||
|
||||
public final class Dir {
|
||||
private Dir() {}
|
||||
|
||||
public static final int NY = 0;
|
||||
public static final int PY = 1;
|
||||
public static final int NZ = 2;
|
||||
public static final int PZ = 3;
|
||||
public static final int NX = 4;
|
||||
public static final int PX = 5;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package mods.immibis.microblocks.api;
|
||||
|
||||
public enum EnumAxisPosition {
|
||||
Negative,
|
||||
Positive,
|
||||
Centre,
|
||||
Span;
|
||||
|
||||
public boolean touchesNegative() {
|
||||
return this == Negative || this == Span;
|
||||
}
|
||||
|
||||
public boolean touchesPositive() {
|
||||
return this == Positive || this == Span;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package mods.immibis.microblocks.api;
|
||||
|
||||
|
||||
public enum EnumPartClass {
|
||||
Centre,
|
||||
Panel,
|
||||
HollowPanel,
|
||||
Strip,
|
||||
Corner
|
||||
}
|
||||
@@ -0,0 +1,131 @@
|
||||
package mods.immibis.microblocks.api;
|
||||
|
||||
import static mods.immibis.microblocks.api.EnumAxisPosition.*;
|
||||
import static mods.immibis.microblocks.api.EnumPositionClass.*;
|
||||
import mods.immibis.core.api.util.Dir;
|
||||
|
||||
public enum EnumPosition {
|
||||
// DO NOT CHANGE ORDER - Ordinals are saved in NBT
|
||||
// Changing order WILL break existing saves!
|
||||
|
||||
Centre(EnumAxisPosition.Centre, EnumAxisPosition.Centre, EnumAxisPosition.Centre, EnumPositionClass.Centre),
|
||||
FaceNX(Negative, Span, Span, Face),
|
||||
FacePX(Positive, Span, Span, Face),
|
||||
FaceNY(Span, Negative, Span, Face),
|
||||
FacePY(Span, Positive, Span, Face),
|
||||
FaceNZ(Span, Span, Negative, Face),
|
||||
FacePZ(Span, Span, Positive, Face),
|
||||
EdgeNXNY(Negative, Negative, Span, Edge),
|
||||
EdgeNXPY(Negative, Positive, Span, Edge),
|
||||
EdgePXNY(Positive, Negative, Span, Edge),
|
||||
EdgePXPY(Positive, Positive, Span, Edge),
|
||||
EdgeNXNZ(Negative, Span, Negative, Edge),
|
||||
EdgeNXPZ(Negative, Span, Positive, Edge),
|
||||
EdgePXNZ(Positive, Span, Negative, Edge),
|
||||
EdgePXPZ(Positive, Span, Positive, Edge),
|
||||
EdgeNYNZ(Span, Negative, Negative, Edge),
|
||||
EdgeNYPZ(Span, Negative, Positive, Edge),
|
||||
EdgePYNZ(Span, Positive, Negative, Edge),
|
||||
EdgePYPZ(Span, Positive, Positive, Edge),
|
||||
CornerNXNYNZ(Negative, Negative, Negative, Corner),
|
||||
CornerNXNYPZ(Negative, Negative, Positive, Corner),
|
||||
CornerNXPYNZ(Negative, Positive, Negative, Corner),
|
||||
CornerNXPYPZ(Negative, Positive, Positive, Corner),
|
||||
CornerPXNYNZ(Positive, Negative, Negative, Corner),
|
||||
CornerPXNYPZ(Positive, Negative, Positive, Corner),
|
||||
CornerPXPYNZ(Positive, Positive, Negative, Corner),
|
||||
CornerPXPYPZ(Positive, Positive, Positive, Corner),
|
||||
|
||||
PostX(Span, EnumAxisPosition.Centre, EnumAxisPosition.Centre, Post),
|
||||
PostY(EnumAxisPosition.Centre, Span, EnumAxisPosition.Centre, Post),
|
||||
PostZ(EnumAxisPosition.Centre, EnumAxisPosition.Centre, Span, Post),
|
||||
|
||||
;
|
||||
|
||||
private EnumPosition(EnumAxisPosition x, EnumAxisPosition y, EnumAxisPosition z, EnumPositionClass clazz) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
this.clazz = clazz;
|
||||
}
|
||||
|
||||
public final EnumAxisPosition x, y, z;
|
||||
public final EnumPositionClass clazz;
|
||||
|
||||
public static EnumPosition getCornerPosition(int x, int y, int z) {
|
||||
if(x < 0)
|
||||
if(y < 0)
|
||||
if(z < 0)
|
||||
return CornerNXNYNZ;
|
||||
else
|
||||
return CornerNXNYPZ;
|
||||
else
|
||||
if(z < 0)
|
||||
return CornerNXPYNZ;
|
||||
else
|
||||
return CornerNXPYPZ;
|
||||
else
|
||||
if(y < 0)
|
||||
if(z < 0)
|
||||
return CornerPXNYNZ;
|
||||
else
|
||||
return CornerPXNYPZ;
|
||||
else
|
||||
if(z < 0)
|
||||
return CornerPXPYNZ;
|
||||
else
|
||||
return CornerPXPYPZ;
|
||||
}
|
||||
|
||||
private static EnumPosition edgePositionLookup[][] = {
|
||||
{null, null, EdgeNYNZ, EdgeNYPZ, EdgeNXNY, EdgePXNY},
|
||||
{null, null, EdgePYNZ, EdgePYPZ, EdgeNXPY, EdgePXPY},
|
||||
{EdgeNYNZ, EdgePYNZ, null, null, EdgeNXNZ, EdgePXNZ},
|
||||
{EdgeNYPZ, EdgePYPZ, null, null, EdgeNXPZ, EdgePXPZ},
|
||||
{EdgeNXNY, EdgeNXPY, EdgeNXNZ, EdgeNXPZ, null, null},
|
||||
{EdgePXNY, EdgePXPY, EdgePXNZ, EdgePXPZ, null, null},
|
||||
};
|
||||
|
||||
private static boolean edgeTouches(EnumPosition edge, int face) {
|
||||
switch(face) {
|
||||
case Dir.NX: return edge.x == EnumAxisPosition.Negative;
|
||||
case Dir.PX: return edge.x == EnumAxisPosition.Positive;
|
||||
case Dir.NY: return edge.y == EnumAxisPosition.Negative;
|
||||
case Dir.PY: return edge.y == EnumAxisPosition.Positive;
|
||||
case Dir.NZ: return edge.z == EnumAxisPosition.Negative;
|
||||
case Dir.PZ: return edge.z == EnumAxisPosition.Positive;
|
||||
}
|
||||
throw new IllegalArgumentException("Invalid face "+face);
|
||||
}
|
||||
|
||||
static {
|
||||
for(int a = 0; a < 6; a++)
|
||||
for(int b = 0; b < 6; b++)
|
||||
assert(edgePositionLookup[a][b] == null || (edgeTouches(edgePositionLookup[a][b], a) && edgeTouches(edgePositionLookup[a][b], b)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the edge microblock position that intersects both the given faces.
|
||||
*
|
||||
* @param side1 One of the faces.
|
||||
* @param side2 The other face.
|
||||
* @return The matching microblock position, or null for invalid face combinations (eg +Y and -Y)
|
||||
*/
|
||||
public static EnumPosition getEdgePosition(int side1, int side2) {
|
||||
if(side1 < 0 || side2 < 0 || side1 > 5 || side2 > 5)
|
||||
return null;
|
||||
return edgePositionLookup[side2][side1];
|
||||
}
|
||||
|
||||
public static EnumPosition getFacePosition(int side) {
|
||||
switch(side) {
|
||||
case Dir.NX: return FaceNX;
|
||||
case Dir.PX: return FacePX;
|
||||
case Dir.NY: return FaceNY;
|
||||
case Dir.PY: return FacePY;
|
||||
case Dir.NZ: return FaceNZ;
|
||||
case Dir.PZ: return FacePZ;
|
||||
default: throw new IllegalArgumentException("Invalid direction: "+side);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package mods.immibis.microblocks.api;
|
||||
|
||||
|
||||
public enum EnumPositionClass {
|
||||
Centre,
|
||||
Face,
|
||||
Edge,
|
||||
Corner,
|
||||
Post,
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
package mods.immibis.microblocks.api;
|
||||
|
||||
|
||||
import java.io.DataInput;
|
||||
import java.io.DataOutput;
|
||||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
|
||||
import mods.immibis.core.api.multipart.ICoverSystem;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
/** Not intended to be implemented outside of the Immibis's Microblocks mod. */
|
||||
public interface IMicroblockCoverSystem extends ICoverSystem, IMicroblockIntegratedTile {
|
||||
/**
|
||||
* Returns the position of a part.
|
||||
*
|
||||
* @param part The part number.
|
||||
* @return The part's position, or null if it's an invalid part.
|
||||
*/
|
||||
@Override
|
||||
EnumPosition getPartPosition(int part);
|
||||
|
||||
boolean addPart(Part part);
|
||||
|
||||
/**
|
||||
* Returns true if tubes/cables/etc that use the centre of the block
|
||||
* can connect through the specified side - ie if it is not blocked by a non-hollow cover.
|
||||
*/
|
||||
boolean isSideOpen(int side);
|
||||
|
||||
/**
|
||||
* Serializes the microblocks to a byte array.
|
||||
*/
|
||||
byte[] writeDescriptionBytes();
|
||||
|
||||
/**
|
||||
* Unserializes the microblocks from a byte array.
|
||||
*/
|
||||
void readDescriptionBytes(byte[] data, int start);
|
||||
|
||||
/**
|
||||
* Serializes the microblocks to a DataOutput.
|
||||
*/
|
||||
void writeDescriptionPacket(DataOutput data) throws IOException;
|
||||
|
||||
/**
|
||||
* Unserializes the microblocks from a DataInput.
|
||||
*/
|
||||
void readDescriptionPacket(DataInput data) throws IOException;
|
||||
|
||||
/**
|
||||
* Serializes the microblocks to NBT.
|
||||
* Data will be stored in the "ICMP" key of the given compound tag.
|
||||
*/
|
||||
void writeToNBT(NBTTagCompound tag);
|
||||
|
||||
/**
|
||||
* Unserializes the microblocks from NBT.
|
||||
* Data will be read from the "ICMP" key of the given compound tag.
|
||||
*/
|
||||
void readFromNBT(NBTTagCompound tag);
|
||||
|
||||
/**
|
||||
* Returns true if there is a part in the specified position.
|
||||
*/
|
||||
boolean isPositionOccupied(EnumPosition pos);
|
||||
|
||||
/**
|
||||
* Returns all parts in this block.
|
||||
*/
|
||||
Collection<Part> getAllParts();
|
||||
|
||||
/**
|
||||
* Checks if an edge is unused (for example, if wire connections can connect around corners through it)
|
||||
* Returns the same result if face1 and face2 are swapped.
|
||||
*
|
||||
* @param face1 One face bordering the edge to check.
|
||||
* @param face2 The other face bordering the edge to check.
|
||||
* @return True if the edge is unused.
|
||||
*/
|
||||
public boolean isEdgeOpen(int face1, int face2);
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package mods.immibis.microblocks.api;
|
||||
|
||||
/**
|
||||
* If you have an IMicroblockSupporterTile that is also an IPartContainer,
|
||||
* you should implement this for better integration.
|
||||
*
|
||||
* You might, in rare circumstances, want to implement it just for isPositionOccupied, without being an IPartContainer.
|
||||
*/
|
||||
public interface IMicroblockIntegratedTile {
|
||||
/**
|
||||
* Returns the microblock position a tile-owned part mainly occupies, or null if
|
||||
* unknown or the part occupies the whole block.
|
||||
* Used to determine the position of new microblocks placed by the player.
|
||||
*
|
||||
* If this tile doesn't implement IPartContainer as well, this is never called.
|
||||
*
|
||||
* @param subHit The part index.
|
||||
* @return The position the part occupies.
|
||||
*/
|
||||
public EnumPosition getPartPosition(int index);
|
||||
|
||||
/**
|
||||
* Returns true if the given position is occupied by the tile.
|
||||
* Does not check for collisions with other positions.
|
||||
*/
|
||||
public boolean isPositionOccupied(EnumPosition pos);
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package mods.immibis.microblocks.api;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public interface IMicroblockPermissionHandler {
|
||||
/**
|
||||
* Returns true if this permission handler wants to prevent placing a microblock.
|
||||
* This is called on both the client and the server.
|
||||
*
|
||||
* @param player The player placing a part.
|
||||
* @param w The world.
|
||||
* @param x The x coordinate of the microblock container block.
|
||||
* @param y The y coordinate of the microblock container block.
|
||||
* @param z The z coordinate of the microblock container block.
|
||||
* @param p The part being placed.
|
||||
*/
|
||||
public boolean doesPreventPlacing(EntityPlayer player, World w, int x, int y, int z, Part p);
|
||||
|
||||
/**
|
||||
* Returns true if this permission handler wants to prevent breaking a microblock.
|
||||
* This is called on both the client and the server.
|
||||
*
|
||||
* Not currently implemented. If you want to use this, get immibis to finish it.
|
||||
*
|
||||
* @param player The player breaking a part.
|
||||
* @param w The world.
|
||||
* @param x The x coordinate of the microblock container block.
|
||||
* @param y The y coordinate of the microblock container block.
|
||||
* @param z The z coordinate of the microblock container block.
|
||||
* @param tile The microblock container tile entity.
|
||||
* @param p The part being broken.
|
||||
*/
|
||||
public boolean doesPreventBreaking(EntityPlayer player, World w, int x, int y, int z, IMicroblockSupporterTile tile, Part p);
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package mods.immibis.microblocks.api;
|
||||
|
||||
import mods.immibis.core.api.multipart.ICoverableTile;
|
||||
|
||||
/**
|
||||
* A multipart tile that is compatible with microblocks.
|
||||
* Only tile entities should implement this.
|
||||
*/
|
||||
public interface IMicroblockSupporterTile extends ICoverableTile {
|
||||
/**
|
||||
* Returns true if the tile is "in the way" of this part and will prevent it being placed.
|
||||
* @param type The type of part being placed.
|
||||
* @param pos The position the part is being placed in.
|
||||
* @return False to prevent part placement, otherwise true.
|
||||
*/
|
||||
public boolean isPlacementBlocked(PartType<?> type, EnumPosition pos);
|
||||
|
||||
@Override
|
||||
public IMicroblockCoverSystem getCoverSystem();
|
||||
|
||||
/**
|
||||
* Called after microblocks are added or removed.
|
||||
*
|
||||
* You should probably at least call World.markBlockForUpdate and world.notifyBlocksOfNeighborChange.
|
||||
*/
|
||||
public void onMicroblocksChanged();
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package mods.immibis.microblocks.api;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public interface IMicroblockSystem {
|
||||
|
||||
/**
|
||||
* Creates a microblock ICoverSystem.
|
||||
* @param tile The tile entity this IMicroblockCoverSystem is for.
|
||||
*/
|
||||
IMicroblockCoverSystem createMicroblockCoverSystem(IMicroblockSupporterTile tile);
|
||||
|
||||
/**
|
||||
* Allows the given block to be cut up.
|
||||
* Your block must have a reasonable implementation of getBlockTextureFromSideAndMetadata.
|
||||
* Part IDs will be assigned automatically based on the block ID and metadata value.
|
||||
*/
|
||||
void addCuttableBlock(Block block, int meta);
|
||||
|
||||
/**
|
||||
* Returns a part type, given its ID.
|
||||
*/
|
||||
PartType<?> getPartTypeByID(int id);
|
||||
|
||||
Block getMicroblockContainerBlock();
|
||||
|
||||
|
||||
/**
|
||||
* Registers a custom part type.
|
||||
* @throw IllegalArgumentException if the part type ID is already in use.
|
||||
*/
|
||||
void registerPartType(PartType<?> type) throws IllegalArgumentException;
|
||||
|
||||
|
||||
/**
|
||||
* Creates an item stack of microblocks with the given part type ID and stack size.
|
||||
* @throw IllegalArgumentException if there is no part type with the given ID.
|
||||
*/
|
||||
ItemStack partTypeIDToItemStack(int id, int stackSize) throws IllegalArgumentException;
|
||||
|
||||
/**
|
||||
* Gets the part ID from an item stack.
|
||||
* @throw NullPointerException if stack == null
|
||||
* @throw IllegalArgumentException if stack is not a stack of microblocks
|
||||
*/
|
||||
int itemStackToPartID(ItemStack stack) throws NullPointerException, IllegalArgumentException;
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package mods.immibis.microblocks.api;
|
||||
|
||||
public interface IMicroblockSystem2 extends IMicroblockSystem {
|
||||
/**
|
||||
* Adds a microblock permission handler.
|
||||
*
|
||||
* You cannot register two permission handlers with the same name.
|
||||
* You are recommended to make the name start with your mod ID.
|
||||
* You are recommended to make the name human readable.
|
||||
*
|
||||
* This method may be called from any thread at any time.
|
||||
*
|
||||
* @param name A name identifying this permission handler.
|
||||
* @param handler The permission handler object.
|
||||
*
|
||||
* @throws IllegalArgumentException If <var>name</var> is null, <var>handler</var> is null, or
|
||||
* a permission handler is already registered with the same name, or
|
||||
* the permission handler is already registered.
|
||||
*/
|
||||
public void addPermissionHandler(String name, IMicroblockPermissionHandler handler);
|
||||
|
||||
/**
|
||||
* Removes a permission handler.
|
||||
*
|
||||
* This method may be called from any thread at any time.
|
||||
*
|
||||
* @param handler The permission handler object.
|
||||
*
|
||||
* @throws IllegalArgumentException If <var>handler</var> is null, or the permission handler is not registered.
|
||||
*/
|
||||
public void removePermissionHandler(IMicroblockPermissionHandler handler);
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
package mods.immibis.microblocks.api;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class MicroblockAPIUtils {
|
||||
private static IMicroblockSystem cachedIMS;
|
||||
private static boolean haveCachedIMS;
|
||||
public static synchronized IMicroblockSystem getMicroblockSystem() {
|
||||
if(!haveCachedIMS) {
|
||||
try {
|
||||
cachedIMS = (IMicroblockSystem)Class.forName("mods.immibis.microblocks.MicroblockSystem").getField("instance").get(null);
|
||||
haveCachedIMS = true;
|
||||
} catch(ClassNotFoundException e) {
|
||||
cachedIMS = null;
|
||||
haveCachedIMS = true;
|
||||
} catch(RuntimeException e) {
|
||||
throw e;
|
||||
} catch(Exception e) {
|
||||
throw (AssertionError)new AssertionError("should not happen").initCause(e);
|
||||
}
|
||||
}
|
||||
return cachedIMS;
|
||||
}
|
||||
|
||||
public static IMicroblockCoverSystem createMicroblockCoverSystem(IMicroblockSupporterTile tile) {
|
||||
IMicroblockSystem ims = getMicroblockSystem();
|
||||
return ims == null ? null : ims.createMicroblockCoverSystem(tile);
|
||||
}
|
||||
|
||||
public static Block getMicroblockContainerBlock() {
|
||||
IMicroblockSystem ims = getMicroblockSystem();
|
||||
return ims == null ? null : ims.getMicroblockContainerBlock();
|
||||
}
|
||||
|
||||
public static PartType<?> getPartTypeByID(int i) {
|
||||
IMicroblockSystem ims = getMicroblockSystem();
|
||||
return ims == null ? null : ims.getPartTypeByID(i);
|
||||
}
|
||||
|
||||
/**
|
||||
* If there is a microblock container block at the specified coordinates, this function will save the parts in that block,
|
||||
* place a new block, restore the parts, and return true.
|
||||
* If there is not a microblock container block at the specified coordinates, or placing the block fails, it will
|
||||
* return false.
|
||||
* The new block must have a tile entity which implements IMicroblockSupporterTile and has a non-null IMicroblockCoverSystem.
|
||||
*/
|
||||
public static boolean mergeIntoMicroblockContainer(ItemStack itemstack, EntityPlayer entityplayer, World world, int x, int y, int z, int l, Block newBlock, int newMetadata)
|
||||
{
|
||||
Block microblockContainerBlock = getMicroblockContainerBlock();
|
||||
if(microblockContainerBlock == null || world.getBlock(x, y, z) != microblockContainerBlock)
|
||||
return false;
|
||||
|
||||
IMicroblockSupporterTile tm = (IMicroblockSupporterTile)world.getTileEntity(x, y, z);
|
||||
IMicroblockCoverSystem oldCI = tm.getCoverSystem();
|
||||
if(!world.setBlock(x, y, z, newBlock, newMetadata, 2))
|
||||
return false;
|
||||
|
||||
IMicroblockSupporterTile tcb = (IMicroblockSupporterTile)world.getTileEntity(x, y, z);
|
||||
IMicroblockCoverSystem newCI = tcb.getCoverSystem();
|
||||
|
||||
for(Part p : oldCI.getAllParts())
|
||||
newCI.addPart(p);
|
||||
|
||||
newBlock.onBlockPlacedBy(world, x, y, z, entityplayer, itemstack);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
package mods.immibis.microblocks.api;
|
||||
|
||||
import java.io.DataOutput;
|
||||
|
||||
import net.minecraft.client.particle.EffectRenderer;
|
||||
import net.minecraft.nbt.NBTBase;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
public class Part {
|
||||
public final PartType<?> type;
|
||||
public final EnumPosition pos;
|
||||
|
||||
public Part(PartType<?> type, EnumPosition pos) {
|
||||
this.type = type;
|
||||
this.pos = pos;
|
||||
}
|
||||
|
||||
private static double getMinFromAxisPosition(EnumAxisPosition ap, double size) {
|
||||
switch(ap) {
|
||||
case Span:
|
||||
case Negative:
|
||||
return 0;
|
||||
case Positive:
|
||||
return 1 - size;
|
||||
case Centre:
|
||||
return (1 - size) / 2;
|
||||
default:
|
||||
throw new IllegalArgumentException("ap");
|
||||
}
|
||||
}
|
||||
private static double getMaxFromAxisPosition(EnumAxisPosition ap, double size) {
|
||||
switch(ap) {
|
||||
case Span:
|
||||
case Positive:
|
||||
return 1;
|
||||
case Negative:
|
||||
return size;
|
||||
case Centre:
|
||||
return (1 + size) / 2;
|
||||
default:
|
||||
throw new IllegalArgumentException("ap");
|
||||
}
|
||||
}
|
||||
|
||||
public AxisAlignedBB getBoundingBoxFromPool() {
|
||||
return getBoundingBoxFromPool(pos, type.getSize());
|
||||
}
|
||||
|
||||
public static AxisAlignedBB getBoundingBoxFromPool(EnumPosition pos, double size) {
|
||||
double minx = getMinFromAxisPosition(pos.x, size);
|
||||
double miny = getMinFromAxisPosition(pos.y, size);
|
||||
double minz = getMinFromAxisPosition(pos.z, size);
|
||||
double maxx = getMaxFromAxisPosition(pos.x, size);
|
||||
double maxy = getMaxFromAxisPosition(pos.y, size);
|
||||
double maxz = getMaxFromAxisPosition(pos.z, size);
|
||||
return AxisAlignedBB.getBoundingBox(minx, miny, minz, maxx, maxy, maxz);
|
||||
}
|
||||
|
||||
public NBTBase writeToNBT() {
|
||||
NBTTagCompound c = new NBTTagCompound();
|
||||
c.setInteger("type", type.getID());
|
||||
c.setByte("pos", (byte)pos.ordinal());
|
||||
return c;
|
||||
}
|
||||
|
||||
public static Part readFromNBT(NBTBase tag) {
|
||||
NBTTagCompound c = (NBTTagCompound)tag;
|
||||
PartType<?> type = MicroblockAPIUtils.getMicroblockSystem().getPartTypeByID(c.getInteger("type"));
|
||||
if(type == null)
|
||||
return null;
|
||||
EnumPosition pos = EnumPosition.values()[c.getByte("pos")];
|
||||
Part p = type.createPart(pos, c);
|
||||
return p;
|
||||
}
|
||||
|
||||
/**
|
||||
* You can override this in subclasses of Part to send extra data to clients in the description packet.
|
||||
* As this data is included in every description packet, try to keep it short.
|
||||
* The data is received by {@link PartType#createPart(EnumPosition, java.io.DataInput)}.
|
||||
*/
|
||||
public void writeExtraData(DataOutput data) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Implement this to have block destroy particles.
|
||||
*/
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void addPartDestroyEffects(IMicroblockSupporterTile tile, EffectRenderer er) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Implement this to have block hit particles.
|
||||
*/
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void addPartHitEffects(IMicroblockSupporterTile tile, int sideHit, EffectRenderer er) {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
package mods.immibis.microblocks.api;
|
||||
|
||||
import java.io.DataInput;
|
||||
|
||||
import net.minecraft.client.renderer.RenderBlocks;
|
||||
import net.minecraft.client.renderer.RenderGlobal;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
public interface PartType<PartClass extends Part> {
|
||||
public EnumPartClass getPartClass();
|
||||
public double getSize();
|
||||
public int getID();
|
||||
|
||||
public String getLocalizedName(ItemStack stack);
|
||||
|
||||
public boolean canHarvest(EntityPlayer ply, PartClass part);
|
||||
|
||||
/**
|
||||
* Renders the preview of a part of this type.
|
||||
* Previews are shown when the player is holding a microblock stack of this type.
|
||||
*
|
||||
* The modelview matrix is set so that 0,0,0 and 1,1,1 are the corners of the block to render in.
|
||||
* No other OpenGL state is set - in particular blending is disabled.
|
||||
*
|
||||
* @param context The RenderGlobal object.
|
||||
* @param pos The microblock position to render the preview at.
|
||||
* @param stack The item stack the player is holding.
|
||||
*/
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void renderPreview(RenderGlobal context, EnumPosition pos, ItemStack stack);
|
||||
|
||||
/**
|
||||
* Renders the part as an item.
|
||||
* Rendering should be centered within the box (0,0,0) to (1,1,1).
|
||||
*
|
||||
* @param context The RenderBlocks object.
|
||||
* @param stack The item stack.
|
||||
*/
|
||||
@SideOnly(Side.CLIENT)
|
||||
void renderPartInv(RenderBlocks context, ItemStack stack);
|
||||
|
||||
/**
|
||||
* Returns the item stack dropped when a part with this type is broken.
|
||||
*
|
||||
* @param part The part being broken.
|
||||
* @param ply The player who broke the part, or null if unknown.
|
||||
*/
|
||||
public ItemStack getDroppedStack(Part part, EntityPlayer ply);
|
||||
|
||||
/**
|
||||
* @see net.minecraft.block.Block#getPlayerRelativeBlockHardness(EntityPlayer, net.minecraft.world.World, int, int, int)
|
||||
*/
|
||||
public float getPlayerRelativeHardness(Part part, EntityPlayer ply);
|
||||
|
||||
/**
|
||||
* Returns the item picked when a player middle-clicks on this part in creative.
|
||||
*/
|
||||
public ItemStack getPickItem(Part part);
|
||||
|
||||
/**
|
||||
* Renders a part with this type in the world.
|
||||
* @param render The RenderBlocks object.
|
||||
* @param p The part to render.
|
||||
* @param x The X coordinate of the block containing the part.
|
||||
* @param y The Y coordinate of the block containing the part.
|
||||
* @param z The Z coordinate of the block containing the part.
|
||||
* @param dontRenderSides An array of booleans corresponding to directions.
|
||||
* If dontRenderSides[direction] is true, then that side should not be rendered if it touches the edge of the block space.
|
||||
*/
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void renderPartWorld(RenderBlocks render, Part p, int x, int y, int z, boolean[] dontRenderSides);
|
||||
|
||||
/**
|
||||
* Creates a part with this type and deserializes any extra data that you may have written in {@link Part#writeExtraData()}.
|
||||
* Intended to allow mods to use custom subclasses of Part.
|
||||
*/
|
||||
@SideOnly(Side.CLIENT)
|
||||
public Part createPart(EnumPosition pos, DataInput data);
|
||||
|
||||
/**
|
||||
* Creates a part with this type.
|
||||
* Intended to allow mods to use custom subclasses of Part.
|
||||
*/
|
||||
public Part createPart(EnumPosition pos);
|
||||
|
||||
/**
|
||||
* Creates a part with this type and deserializes any extra data from NBT.
|
||||
* Intended to allow mods to use custom subclasses of Part.
|
||||
*/
|
||||
public Part createPart(EnumPosition pos, NBTTagCompound c);
|
||||
|
||||
/**
|
||||
* Returns true if this part is completely opaque.
|
||||
*/
|
||||
public boolean isOpaque();
|
||||
|
||||
/**
|
||||
* Returns true if this player can harvest this part.
|
||||
*/
|
||||
public boolean canHarvest(Part part, EntityPlayer entityPlayer);
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package mods.immibis.microblocks.api;
|
||||
|
||||
public interface PartType2<PartClass extends Part> extends PartType<PartClass> {
|
||||
/**
|
||||
* @return The light level emitted by this part, from 0 to 15.
|
||||
*/
|
||||
public int getLightLevel();
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
package mods.immibis.microblocks.api.util;
|
||||
|
||||
|
||||
import mods.immibis.microblocks.api.IMicroblockCoverSystem;
|
||||
import mods.immibis.microblocks.api.IMicroblockSupporterTile;
|
||||
import mods.immibis.microblocks.api.IMicroblockSystem;
|
||||
import mods.immibis.microblocks.api.MicroblockAPIUtils;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.network.NetworkManager;
|
||||
import net.minecraft.network.Packet;
|
||||
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
||||
/**
|
||||
* Convenience class for microblock supporting tiles.
|
||||
* Handles creating an ICoverSystem, saving and loading it,
|
||||
* and implements getCollidingBoundingBoxes and collisionRayTrace.
|
||||
*/
|
||||
public abstract class TileCoverableBase extends TileEntity implements IMicroblockSupporterTile {
|
||||
|
||||
protected IMicroblockCoverSystem cover;
|
||||
|
||||
public TileCoverableBase() {
|
||||
IMicroblockSystem ims = MicroblockAPIUtils.getMicroblockSystem();
|
||||
if(ims != null)
|
||||
cover = ims.createMicroblockCoverSystem(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound tag) {
|
||||
super.writeToNBT(tag);
|
||||
if(cover != null)
|
||||
cover.writeToNBT(tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Packet getDescriptionPacket() {
|
||||
if(cover == null)
|
||||
return null;
|
||||
|
||||
NBTTagCompound tag = new NBTTagCompound();
|
||||
tag.setByteArray("C", cover.writeDescriptionBytes());
|
||||
S35PacketUpdateTileEntity p = new S35PacketUpdateTileEntity(xCoord, yCoord, zCoord, 0, tag);
|
||||
return p;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt) {
|
||||
if(cover != null)
|
||||
cover.readDescriptionBytes(pkt.func_148857_g().getByteArray("C"), 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound tag) {
|
||||
super.readFromNBT(tag);
|
||||
if(cover != null)
|
||||
cover.readFromNBT(tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMicroblockCoverSystem getCoverSystem() {
|
||||
return cover;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMicroblocksChanged() {
|
||||
worldObj.notifyBlocksOfNeighborChange(xCoord, yCoord, zCoord, getBlockType());
|
||||
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
|
||||
}
|
||||
|
||||
public void convertToCoverContainerBlock() {
|
||||
if(getCoverSystem() != null)
|
||||
getCoverSystem().convertToContainerBlock();
|
||||
else
|
||||
worldObj.setBlockToAir(xCoord, yCoord, zCoord);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package mods.immibis.microblocks.api.util;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
import net.minecraft.util.MovingObjectPosition;
|
||||
import net.minecraft.util.Vec3;
|
||||
import mods.immibis.core.api.multipart.IPartContainer;
|
||||
import mods.immibis.microblocks.api.IMicroblockIntegratedTile;
|
||||
|
||||
public abstract class TileCoverableMultipartBase extends TileCoverableBase implements IPartContainer, IMicroblockIntegratedTile {
|
||||
protected abstract int getNumTileOwnedParts();
|
||||
|
||||
private static MovingObjectPosition getCloserMOP(MovingObjectPosition a, MovingObjectPosition b, Vec3 src) {
|
||||
if(a == null) return b;
|
||||
if(b == null) return a;
|
||||
|
||||
double ciDistSq = a.hitVec.squareDistanceTo(src);
|
||||
double normalDistSq = b.hitVec.squareDistanceTo(src);
|
||||
|
||||
return ciDistSq < normalDistSq ? a : b;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MovingObjectPosition collisionRayTrace(Vec3 src, Vec3 dst) {
|
||||
MovingObjectPosition result = null;
|
||||
|
||||
for(int k = 0, num = getNumTileOwnedParts(); k < num; k++) {
|
||||
AxisAlignedBB partBB = getPartAABBFromPool(k);
|
||||
if(partBB != null) {
|
||||
partBB.offset(xCoord, yCoord, zCoord);
|
||||
MovingObjectPosition intersect = partBB.calculateIntercept(src, dst);
|
||||
if(intersect != null) {
|
||||
intersect.subHit = k;
|
||||
intersect.typeOfHit = MovingObjectPosition.MovingObjectType.BLOCK;
|
||||
intersect.blockX = xCoord;
|
||||
intersect.blockY = yCoord;
|
||||
intersect.blockZ = zCoord;
|
||||
result = getCloserMOP(result, intersect, src);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getCollidingBoundingBoxes(AxisAlignedBB mask, List<AxisAlignedBB> list, Entity entity) {
|
||||
for(int k = 0, num = getNumTileOwnedParts(); k < num; k++) {
|
||||
AxisAlignedBB partBB = getPartAABBFromPool(k);
|
||||
if(partBB != null) {
|
||||
partBB.offset(xCoord, yCoord, zCoord);
|
||||
if(partBB.intersectsWith(mask))
|
||||
list.add(partBB);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user