Removed vanilla multipart compact. (This is why I love modularisation)

This commit is contained in:
modmuss50 2015-06-06 21:56:55 +01:00
parent b45711f3f1
commit 37258cb84c
5 changed files with 0 additions and 575 deletions

View file

@ -1,164 +0,0 @@
/*
* This file was made by modmuss50. View the licence file to see what licence this is is on. You can always ask me if you would like to use part or all of this file in your project.
*/
package techreborn.partSystem.block;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.block.Block;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
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 techreborn.lib.vecmath.Vecs3dCube;
import techreborn.partSystem.ICustomHighlight;
import techreborn.partSystem.IModPart;
import techreborn.partSystem.ModPart;
/**
* Created by mark on 10/12/14.
*/
public class BlockModPart extends BlockContainer implements ICustomHighlight {
public BlockModPart(Material met) {
super(met);
}
public static TileEntityModPart get(IBlockAccess world, int x, int y, int z) {
TileEntity te = world.getTileEntity(x, y, z);
if (te == null)
return null;
if (!(te instanceof TileEntityModPart))
return null;
return (TileEntityModPart) te;
}
@Override
public TileEntity createNewTileEntity(World world, int i) {
return new TileEntityModPart();
}
@SuppressWarnings(
{"rawtypes", "unchecked"})
@Override
public void addCollisionBoxesToList(World world, int x, int y, int z,
AxisAlignedBB bounds, List l, Entity entity) {
TileEntityModPart te = get(world, x, y, z);
if (te == null)
return;
List<Vecs3dCube> boxes = new ArrayList<Vecs3dCube>();
te.addCollisionBoxesToList(boxes, bounds, entity);
for (Vecs3dCube c : boxes)
l.add(c.toAABB());
}
@Override
public boolean isOpaqueCube() {
return false;
}
@Override
public int getRenderType() {
return -1;
}
@Override
// TODO move to array list
public ArrayList<AxisAlignedBB> getBoxes(World world, int x, int y, int z,
EntityPlayer player) {
TileEntityModPart te = get(world, x, y, z);
if (te == null)
return null;
List<Vecs3dCube> boxes = new ArrayList<Vecs3dCube>();
ArrayList<AxisAlignedBB> list = new ArrayList<AxisAlignedBB>();
if (!te.getParts().isEmpty()) {
for (ModPart modPart : te.getParts())
boxes.addAll(modPart.getSelectionBoxes());
for (int i = 0; i < boxes.size(); i++) {
Vecs3dCube cube = boxes.get(i);
list.add(cube.toAABB());
}
}
return list;
}
public void onNeighborBlockChange(World world, int x, int y, int z,
Block block) {
for (ModPart part : get(world, x, y, z).getParts()) {
part.nearByChange();
}
}
@Override
public MovingObjectPosition collisionRayTrace(World wrd, int x, int y,
int z, Vec3 origin, Vec3 direction) {
ArrayList<AxisAlignedBB> aabbs = getBoxes(wrd, x, y, z, null);
MovingObjectPosition closest = null;
for (AxisAlignedBB aabb : aabbs) {
MovingObjectPosition mop = aabb.getOffsetBoundingBox(x, y, z)
.calculateIntercept(origin, direction);
if (mop != null) {
if (closest != null
&& mop.hitVec.distanceTo(origin) < closest.hitVec
.distanceTo(origin)) {
closest = mop;
} else {
closest = mop;
}
}
}
if (closest != null) {
closest.blockX = x;
closest.blockY = y;
closest.blockZ = z;
}
return closest;
}
@Override
public void onBlockAdded(World world, int x, int y, int z) {
for (ModPart part : get(world, x, y, z).getParts()) {
part.onAdded();
}
super.onBlockAdded(world, x, y, z);
}
@Override
public void breakBlock(World world, int x, int y, int z, Block oldid,
int oldmeta) {
for (ModPart part : get(world, x, y, z).getParts()) {
part.onRemoved();
}
super.breakBlock(world, x, y, z, oldid, oldmeta);
}
@Override
public ArrayList<ItemStack> getDrops(World world, int x, int y, int z,
int metadata, int fortune) {
ArrayList<ItemStack> l = new ArrayList<ItemStack>();
TileEntityModPart te = get(world, x, y, z);
if (te != null) {
for (IModPart p : te.getParts()) {
ItemStack item = p.getItem();
if (item != null)
l.add(item);
}
}
return l;
}
}

View file

@ -1,30 +0,0 @@
/*
* This file was made by modmuss50. View the licence file to see what licence this is is on. You can always ask me if you would like to use part or all of this file in your project.
*/
package techreborn.partSystem.block;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.tileentity.TileEntity;
import org.lwjgl.opengl.GL11;
import techreborn.lib.vecmath.Vecs3d;
import techreborn.partSystem.ModPart;
public class RenderModPart extends TileEntitySpecialRenderer {
@Override
public void renderTileEntityAt(TileEntity tileEntity, double x, double y,
double z, float delta) {
TileEntityModPart te = (TileEntityModPart) tileEntity;
GL11.glPushMatrix();
GL11.glTranslated(x, y, z);
{
for (ModPart modPart : te.getParts()) {
modPart.renderDynamic(new Vecs3d(0, 0, 0), delta);
}
}
GL11.glPopMatrix();
}
}

View file

@ -1,252 +0,0 @@
/*
* This file was made by modmuss50. View the licence file to see what licence this is is on. You can always ask me if you would like to use part or all of this file in your project.
*/
package techreborn.partSystem.block;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import net.minecraft.entity.Entity;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.network.NetworkManager;
import net.minecraft.network.Packet;
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.world.World;
import techreborn.lib.Location;
import techreborn.lib.vecmath.Vecs3dCube;
import techreborn.partSystem.ModPart;
import techreborn.partSystem.ModPartRegistry;
import techreborn.partSystem.parts.CablePart;
import techreborn.partSystem.parts.NullPart;
public class TileEntityModPart extends TileEntity {
private Map<String, ModPart> parts = new HashMap<String, ModPart>();
public void addCollisionBoxesToList(List<Vecs3dCube> l,
AxisAlignedBB bounds, Entity entity) {
if (getParts().size() == 0)
addPart(new NullPart());
List<Vecs3dCube> boxes2 = new ArrayList<Vecs3dCube>();
for (ModPart mp : getParts()) {
List<Vecs3dCube> boxes = new ArrayList<Vecs3dCube>();
mp.addCollisionBoxesToList(boxes, entity);
for (int i = 0; i < boxes.size(); i++) {
Vecs3dCube cube = boxes.get(i).clone();
cube.add(getX(), getY(), getZ());
boxes2.add(cube);
}
}
for (Vecs3dCube c : boxes2) {
// if (c.toAABB().intersectsWith(bounds))
l.add(c);
}
}
public List<Vecs3dCube> getOcclusionBoxes() {
List<Vecs3dCube> boxes = new ArrayList<Vecs3dCube>();
for (ModPart mp : getParts()) {
boxes.addAll(mp.getOcclusionBoxes());
}
return boxes;
}
@Override
public AxisAlignedBB getRenderBoundingBox() {
return AxisAlignedBB.getBoundingBox(xCoord, yCoord, zCoord, xCoord + 1,
yCoord + 1, zCoord + 1);
}
public World getWorld() {
return getWorldObj();
}
public int getX() {
return xCoord;
}
public int getY() {
return yCoord;
}
public int getZ() {
return zCoord;
}
@Override
public void updateEntity() {
if (parts.isEmpty()) {
worldObj.setBlockToAir(xCoord, yCoord, zCoord);
}
for (ModPart mp : getParts()) {
if (mp.world != null && mp.location != null) {
mp.tick();
}
}
}
@Override
public void writeToNBT(NBTTagCompound tag) {
super.writeToNBT(tag);
NBTTagList l = new NBTTagList();
writeParts(l, false);
tag.setTag("parts", l);
}
@Override
public void readFromNBT(NBTTagCompound tag) {
super.readFromNBT(tag);
NBTTagList l = tag.getTagList("parts", new NBTTagCompound().getId());
try {
readParts(l);
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InstantiationException e) {
e.printStackTrace();
}
}
private void writeParts(NBTTagList l, boolean update) {
for (ModPart p : getParts()) {
String id = getIdentifier(p);
NBTTagCompound tag = new NBTTagCompound();
tag.setString("id", id);
tag.setString("type", p.getName());
NBTTagCompound data = new NBTTagCompound();
p.writeToNBT(data);
tag.setTag("data", data);
l.appendTag(tag);
}
}
private void readParts(NBTTagList l) throws IllegalAccessException,
InstantiationException {
for (int i = 0; i < l.tagCount(); i++) {
NBTTagCompound tag = l.getCompoundTagAt(i);
String id = tag.getString("id");
ModPart p = getPart(id);
if (p == null) {
for (ModPart modPart : ModPartRegistry.parts) {
if (modPart.getName().equals(id)) {
p = modPart.getClass().newInstance();
}
}
if (p == null)
continue;
addPart(p);
}
NBTTagCompound data = tag.getCompoundTag("data");
p.readFromNBT(data);
}
}
public void addPart(ModPart modPart) {
ModPart newPart = null;
try {
if(modPart instanceof CablePart){
try {
newPart = modPart.getClass().getDeclaredConstructor(int.class).newInstance(((CablePart) modPart).type);
} catch (InvocationTargetException e) {
e.printStackTrace();
} catch (NoSuchMethodException e) {
e.printStackTrace();
}
} else {
newPart = modPart.getClass().newInstance();
}
newPart.setWorld(getWorldObj());
newPart.setLocation(new Location(xCoord, yCoord, zCoord));
parts.put(newPart.getName(), newPart);
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
private ModPart getPart(String id) {
for (String s : parts.keySet())
if (s.equals(id))
return parts.get(s);
return null;
}
private String getIdentifier(ModPart part) {
for (String s : parts.keySet())
if (parts.get(s).equals(part))
return s;
return null;
}
@Override
public Packet getDescriptionPacket() {
NBTTagCompound tag = new NBTTagCompound();
writeToNBT(tag);
return new S35PacketUpdateTileEntity(xCoord, yCoord, zCoord, 0, tag);
}
@Override
public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt) {
readFromNBT(pkt.func_148857_g());
}
public List<ModPart> getParts() {
List<ModPart> parts = new ArrayList<ModPart>();
for (String s : this.parts.keySet()) {
ModPart p = this.parts.get(s);
parts.add(p);
}
return parts;
}
public List<String> getPartsByName() {
List<String> parts = new ArrayList<String>();
for (String s : this.parts.keySet()) {
parts.add(s);
}
return parts;
}
public boolean canAddPart(ModPart modpart) {
List<Vecs3dCube> cubes = new ArrayList<Vecs3dCube>();
modpart.addCollisionBoxesToList(cubes, null);
for (Vecs3dCube c : cubes)
if (c != null
&& !getWorld().checkNoEntityCollision(
c.clone().add(getX(), getY(), getZ()).toAABB()))
return false;
List<Vecs3dCube> l = getOcclusionBoxes();
for (Vecs3dCube b : modpart.getOcclusionBoxes())
for (Vecs3dCube c : l)
if (c != null && b != null
&& b.toAABB().intersectsWith(c.toAABB()))
return false;
return true;
}
}

View file

@ -1,126 +0,0 @@
/*
* This file was made by modmuss50. View the licence file to see what licence this is is on. You can always ask me if you would like to use part or all of this file in your project.
*/
package techreborn.partSystem.block;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
import techreborn.lib.Location;
import techreborn.lib.vecmath.Vecs3dCube;
import techreborn.partSystem.IModPart;
import techreborn.partSystem.IPartProvider;
import techreborn.partSystem.ModPart;
import cpw.mods.fml.client.registry.ClientRegistry;
import cpw.mods.fml.common.registry.GameRegistry;
/**
* Created by mark on 10/12/14.
*/
public class WorldProvider implements IPartProvider {
Block blockModPart;
@Override
public String modID() {
return "Minecraft";
}
@Override
public void registerPart() {
// Loads all of the items
blockModPart = new BlockModPart(Material.ground)
.setBlockName("modPartBlock");
GameRegistry.registerBlock(blockModPart, "modPartBlock");
// registers the tile and renderer
GameRegistry.registerTileEntity(TileEntityModPart.class,
"TileEntityModPart");
}
public void clientRegister() {
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityModPart.class,
new RenderModPart());
}
@Override
public boolean checkOcclusion(World world, Location location,
Vecs3dCube cube) {
return true;
}
@Override
public boolean hasPart(World world, Location location, String name) {
TileEntity tileEntity = world.getTileEntity(location.getX(),
location.getY(), location.getZ());
if (tileEntity instanceof TileEntityModPart) {
for (ModPart part : ((TileEntityModPart) tileEntity).getParts()) {
if (part.getName().equals(name)) {
return true;
}
}
}
return false;
}
@Override
public boolean placePart(ItemStack item, EntityPlayer player, World world,
int x, int y, int z, int side, float hitX, float hitY, float hitZ,
ModPart modPart) {
ForgeDirection forgeDirection = ForgeDirection.getOrientation(side);
if (world.getBlock(x + forgeDirection.offsetX, y
+ forgeDirection.offsetY, z + forgeDirection.offsetZ) == Blocks.air) {
TileEntityModPart modPart1;
world.setBlock(x + forgeDirection.offsetX, y
+ forgeDirection.offsetY, z + forgeDirection.offsetZ,
blockModPart);
modPart1 = (TileEntityModPart) world.getTileEntity(x
+ forgeDirection.offsetX, y + forgeDirection.offsetY, z
+ forgeDirection.offsetZ);
// if(modPart1.canAddPart(modPart)){
modPart1.addPart(modPart);
return true;
// }
}
// this adds a part to a block
if (world.getBlock(x, y, z) == blockModPart) {
TileEntityModPart tileEntityModPart = (TileEntityModPart) world
.getTileEntity(x + forgeDirection.offsetX, y
+ forgeDirection.offsetY, z
+ forgeDirection.offsetZ);
if (!tileEntityModPart.getPartsByName().contains(modPart.getName())
&& tileEntityModPart.canAddPart(modPart))
tileEntityModPart.addPart(modPart);
return true;
}
if (world.getBlock(x + forgeDirection.offsetX, y
+ forgeDirection.offsetY, z + forgeDirection.offsetZ) == blockModPart) {
TileEntityModPart tileEntityModPart = (TileEntityModPart) world
.getTileEntity(x + forgeDirection.offsetX, y
+ forgeDirection.offsetY, z
+ forgeDirection.offsetZ);
if (!tileEntityModPart.getPartsByName().contains(modPart.getName())
&& tileEntityModPart.canAddPart(modPart))
tileEntityModPart.addPart(modPart);
return true;
}
return false;
}
@Override
public boolean isTileFromProvider(TileEntity tileEntity) {
return tileEntity instanceof TileEntityModPart;
}
//TODO
@Override
public IModPart getPartFromWorld(World world, Location location, String name) {
return null;
}
}

View file

@ -2,8 +2,6 @@ package techreborn.proxies;
import net.minecraftforge.common.MinecraftForge;
import techreborn.client.IconSupplier;
import techreborn.partSystem.ModPartRegistry;
import techreborn.partSystem.block.WorldProvider;
public class ClientProxy extends CommonProxy {
@ -12,6 +10,5 @@ public class ClientProxy extends CommonProxy {
{
super.init();
MinecraftForge.EVENT_BUS.register(new IconSupplier());
ModPartRegistry.addProvider(new WorldProvider());
}
}