This commit is contained in:
Modmuss50 2015-11-23 14:49:35 +00:00
parent fa9cd98b5a
commit abb9b5102f
65 changed files with 0 additions and 0 deletions

View file

@ -0,0 +1,135 @@
package techreborn.partSystem.fmp;
import codechicken.lib.packet.PacketCustom;
import codechicken.lib.raytracer.RayTracer;
import codechicken.lib.vec.BlockCoord;
import codechicken.lib.vec.Vector3;
import codechicken.multipart.MultiPartRegistry;
import codechicken.multipart.TMultiPart;
import codechicken.multipart.TileMultipart;
import net.minecraftforge.fml.common.eventhandler.EventPriority;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import ic2.api.item.IC2Items;
import ic2.core.block.wiring.BlockCable;
import ic2.core.block.wiring.TileEntityCable;
import net.minecraft.block.Block;
import net.minecraft.block.BlockFence;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.network.play.client.C08PacketPlayerBlockPlacement;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.player.PlayerDestroyItemEvent;
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import reborncore.common.packets.AddDiscriminatorEvent;
import reborncore.common.packets.PacketHandler;
import techreborn.partSystem.parts.CablePart;
import java.util.Arrays;
public class CableConverter implements MultiPartRegistry.IPartConverter {
@Override
public Iterable<Block> blockTypes() {
return Arrays.asList(Block.getBlockFromItem(IC2Items.getItem("copperCableBlock").getItem()));
}
@Override
public TMultiPart convert(World world, BlockCoord blockCoord) {
Block block = world.getBlock(blockCoord.x, blockCoord.y, blockCoord.z);
if (block instanceof BlockCable) {
TileEntity tileEntity = world.getTileEntity(blockCoord.x, blockCoord.y, blockCoord.z);
if (tileEntity instanceof TileEntityCable) {
TileEntityCable cable = (TileEntityCable) tileEntity;
int type = cable.cableType;
CablePart newPart = new CablePart();
newPart.setType(type);
return new FMPModPart(newPart);
}
}
return null;
}
private final ThreadLocal<Object> placing = new ThreadLocal<Object>();
@SubscribeEvent(priority = EventPriority.LOW)
public void playerInteract(PlayerInteractEvent event) {
if (event.action == PlayerInteractEvent.Action.RIGHT_CLICK_BLOCK && event.entityPlayer.worldObj.isRemote) {
if (placing.get() != null) return;//for mods that do dumb stuff and call this event like MFR
placing.set(event);
if (place(event.entityPlayer, event.entityPlayer.worldObj)) event.setCanceled(true);
placing.set(null);
}
}
public static boolean place(EntityPlayer player, World world) {
MovingObjectPosition hit = RayTracer.reTrace(world, player);
if (hit == null) return false;
BlockCoord pos = new BlockCoord(hit.blockX, hit.blockY, hit.blockZ);
ItemStack held = player.getHeldItem();
FMPModPart part = null;
if (held == null) return false;
Item heldItem = held.getItem();
if (heldItem == IC2Items.getItem("copperCableItem").getItem()) {
CablePart cablePart = new CablePart();
cablePart.setType(held.getItemDamage());
part = new FMPModPart(cablePart);
}
if (part == null) return false;
if (world.isRemote && !player.isSneaking())//attempt to use block activated like normal and tell the server the right stuff
{
Vector3 f = new Vector3(hit.hitVec).add(-hit.blockX, -hit.blockY, -hit.blockZ);
Block block = world.getBlock(hit.blockX, hit.blockY, hit.blockZ);
if (!ignoreActivate(block) && block.onBlockActivated(world, hit.blockX, hit.blockY, hit.blockZ, player, hit.sideHit, (float) f.x, (float) f.y, (float) f.z)) {
player.swingItem();
PacketCustom.sendToServer(new C08PacketPlayerBlockPlacement(hit.blockX, hit.blockY, hit.blockZ, hit.sideHit, player.inventory.getCurrentItem(), (float) f.x, (float) f.y, (float) f.z));
return true;
}
}
TileMultipart tile = TileMultipart.getOrConvertTile(world, pos);
if (tile == null || !tile.canAddPart(part)) {
pos = pos.offset(hit.sideHit);
tile = TileMultipart.getOrConvertTile(world, pos);
if (tile == null || !tile.canAddPart(part)) return false;
}
if (!world.isRemote) {
TileMultipart.addPart(world, pos, part);
world.playSoundEffect(pos.x + 0.5, pos.y + 0.5, pos.z + 0.5, Blocks.wool.stepSound.func_150496_b(), (Blocks.wool.stepSound.getVolume() + 1.0F) / 2.0F, Blocks.wool.stepSound.getPitch() * 0.8F);
if (!player.capabilities.isCreativeMode) {
held.stackSize--;
if (held.stackSize == 0) {
player.inventory.mainInventory[player.inventory.currentItem] = null;
MinecraftForge.EVENT_BUS.post(new PlayerDestroyItemEvent(player, held));
}
}
} else {
player.swingItem();
PacketHandler.sendPacketToServer(new PacketFMPPlacePart());
}
return true;
}
/**
* Because vanilla is weird.
*/
private static boolean ignoreActivate(Block block) {
if (block instanceof BlockFence) return true;
return false;
}
@SubscribeEvent
public void addDiscriminator(AddDiscriminatorEvent event) {
event.getPacketHandler().addDiscriminator(event.getPacketHandler().nextDiscriminator, PacketFMPPlacePart.class);
}
}

View file

@ -0,0 +1,141 @@
/*
* 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.fmp;
import codechicken.lib.data.MCDataInput;
import codechicken.lib.vec.BlockCoord;
import codechicken.lib.vec.Cuboid6;
import codechicken.multipart.MultiPartRegistry;
import codechicken.multipart.NormallyOccludedPart;
import codechicken.multipart.TMultiPart;
import codechicken.multipart.TileMultipart;
import net.minecraftforge.fml.common.Loader;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import reborncore.common.misc.Location;
import reborncore.common.misc.vecmath.Vecs3dCube;
import techreborn.partSystem.IModPart;
import techreborn.partSystem.IPartProvider;
import techreborn.partSystem.ModPart;
import techreborn.partSystem.ModPartRegistry;
import java.util.List;
public class FMPFactory implements MultiPartRegistry.IPartFactory2,
IPartProvider {
public TMultiPart createPart(String type, boolean client) {
for (ModPart modPart : ModPartRegistry.parts) {
if (modPart.getName().equals(type)) {
return new FMPModPart((ModPart) modPart.copy());
}
}
return null;
}
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) {
return new FakeFMPPlacerItem(modPart).onItemUse(item, player, world, x,
y, z, side, hitX, hitY, hitZ);
}
@Override
public boolean isTileFromProvider(TileEntity tileEntity) {
return tileEntity instanceof TileMultipart;
}
@Override
public IModPart getPartFromWorld(World world, Location location, String name) {
TileEntity tileEntity = world.getTileEntity(location.getX(),
location.getY(), location.getZ());
if (tileEntity instanceof TileMultipart) {
TileMultipart mp = (TileMultipart) tileEntity;
boolean ret = false;
List<TMultiPart> t = mp.jPartList();
for (TMultiPart p : t) {
if (ret == false) {
if (p.getType().equals(name)) {
if (p instanceof FMPModPart) {
return ((FMPModPart) p).iModPart;
}
ret = true;
}
}
}
return null;
}
return null;
}
@Override
public void init() {
if (Loader.isModLoaded("IC2")) {
MultiPartRegistry.registerConverter(new CableConverter());
MinecraftForge.EVENT_BUS.register(new CableConverter());
}
}
@Override
public String modID() {
return "ForgeMultipart";
}
@Override
public void registerPart() {
for (ModPart modPart : ModPartRegistry.parts) {
MultiPartRegistry.registerParts(new FMPFactory(), new String[]
{modPart.getName()});
}
}
@Override
public boolean checkOcclusion(World world, Location location,
Vecs3dCube cube) {
codechicken.multipart.TileMultipart tmp = codechicken.multipart.TileMultipart
.getOrConvertTile(world, new BlockCoord(location.getX(),
location.getY(), location.getZ()));
if (tmp == null)
return false;
return !tmp.occlusionTest(tmp.partList(), new NormallyOccludedPart(
new Cuboid6(cube.toAABB())));
}
@Override
public boolean hasPart(World world, Location location, String name) {
TileEntity tileEntity = world.getTileEntity(location.getX(),
location.getY(), location.getZ());
if (tileEntity instanceof TileMultipart) {
TileMultipart mp = (TileMultipart) tileEntity;
boolean ret = false;
List<TMultiPart> t = mp.jPartList();
for (TMultiPart p : t) {
if (ret == false) {
if (p.getType().equals(name)) {
ret = true;
}
}
}
return ret;
}
return false;
}
@Override
public TMultiPart createPart(String s, NBTTagCompound nbtTagCompound) {
return createPart(s, false);
}
@Override
public TMultiPart createPart(String s, MCDataInput mcDataInput) {
return createPart(s, false);
}
}

View file

@ -0,0 +1,224 @@
/*
* 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.fmp;
import codechicken.lib.data.MCDataInput;
import codechicken.lib.data.MCDataOutput;
import codechicken.lib.raytracer.IndexedCuboid6;
import codechicken.lib.vec.Cuboid6;
import codechicken.lib.vec.Vector3;
import codechicken.microblock.ISidedHollowConnect;
import codechicken.multipart.JNormalOcclusion;
import codechicken.multipart.NormalOcclusionTest;
import codechicken.multipart.TMultiPart;
import codechicken.multipart.TSlottedPart;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
import reborncore.common.misc.Location;
import reborncore.common.misc.vecmath.Vecs3d;
import reborncore.common.misc.vecmath.Vecs3dCube;
import techreborn.partSystem.IPartDesc;
import techreborn.partSystem.ModPart;
import java.util.ArrayList;
import java.util.List;
public class FMPModPart extends TMultiPart implements TSlottedPart,
JNormalOcclusion, ISidedHollowConnect {
ModPart iModPart;
public FMPModPart(ModPart iModPart) {
this.iModPart = iModPart;
}
@Override
public int getHollowSize(int i) {
return 0;
}
@Override
public Iterable<Cuboid6> getOcclusionBoxes() {
List<Cuboid6> cubes = new ArrayList<Cuboid6>();
for (Vecs3dCube c : iModPart.getOcclusionBoxes())
if (c != null)
cubes.add(new Cuboid6(c.toAABB()));
return cubes;
}
@Override
public boolean occlusionTest(TMultiPart npart) {
return NormalOcclusionTest.apply(this, npart);
}
@Override
public Iterable<Cuboid6> getCollisionBoxes() {
List<Cuboid6> cubes = new ArrayList<Cuboid6>();
List<Vecs3dCube> boxes = new ArrayList<Vecs3dCube>();
iModPart.addCollisionBoxesToList(boxes, null);
for (Vecs3dCube c : boxes) {
if (c != null)
cubes.add(new Cuboid6(c.toAABB()));
}
return cubes;
}
@Override
public Iterable<IndexedCuboid6> getSubParts() {
List<IndexedCuboid6> cubes = new ArrayList<IndexedCuboid6>();
if (iModPart.getSelectionBoxes() != null) {
for (Vecs3dCube c : iModPart.getSelectionBoxes())
if (c != null)
cubes.add(new IndexedCuboid6(0, new Cuboid6(c.toAABB())));
if (cubes.size() == 0)
cubes.add(new IndexedCuboid6(0, new Cuboid6(0, 0, 0, 1, 1, 1)));
}
return cubes;
}
@Override
@SideOnly(Side.CLIENT)
public void renderDynamic(Vector3 pos, float frame, int pass) {
iModPart.renderDynamic(new Vecs3d(pos.x, pos.y, pos.z), frame);
}
@Override
public String getType() {
return iModPart.getName();
}
@Override
public int getSlotMask() {
return 0;
}
public World getWorld() {
return world();
}
public int getX() {
if (iModPart.world == null || iModPart.location == null) {
iModPart.setWorld(world());
iModPart.setLocation(new Location(x(), y(), z()));
}
return x();
}
public int getY() {
if (iModPart.world == null || iModPart.location == null) {
iModPart.setWorld(world());
iModPart.setLocation(new Location(x(), y(), z()));
}
return y();
}
public int getZ() {
if (iModPart.world == null || iModPart.location == null) {
iModPart.setWorld(world());
iModPart.setLocation(new Location(x(), y(), z()));
}
return z();
}
@Override
public void onAdded() {
iModPart.setWorld(world());
iModPart.setLocation(new Location(x(), y(), z()));
iModPart.nearByChange();
iModPart.onAdded();
}
@Override
public void update() {
if (iModPart.location != null) {
iModPart.tick();
}
}
@Override
public void onNeighborChanged() {
super.onNeighborChanged();
if (iModPart.world == null || iModPart.location == null) {
iModPart.setWorld(world());
iModPart.setLocation(new Location(x(), y(), z()));
}
iModPart.nearByChange();
}
public void onRemoved() {
iModPart.onRemoved();
super.onRemoved();
}
@Override
public boolean renderStatic(Vector3 pos, int pass) {
boolean render;
render = iModPart.renderStatic(new Vecs3d((int) pos.x, (int) pos.y, (int) pos.z), pass);
return render;
}
@Override
public Iterable<ItemStack> getDrops() {
List<ItemStack> stackArrayList = new ArrayList<ItemStack>();
if (iModPart.getItem() != null) {
stackArrayList.add(iModPart.getItem().copy());
}
return stackArrayList;
}
@Override
public void onPartChanged(TMultiPart part) {
super.onPartChanged(part);
if (iModPart.world == null || iModPart.location == null) {
iModPart.setWorld(world());
iModPart.setLocation(new Location(x(), y(), z()));
}
iModPart.nearByChange();
}
@Override
public void readDesc(MCDataInput packet) {
super.readDesc(packet);
if (iModPart instanceof IPartDesc) {
((IPartDesc) iModPart).readDesc(packet.readNBTTagCompound());
}
}
@Override
public void writeDesc(MCDataOutput packet) {
super.writeDesc(packet);
if (iModPart instanceof IPartDesc) {
NBTTagCompound tagCompound = new NBTTagCompound();
((IPartDesc) iModPart).writeDesc(tagCompound);
packet.writeNBTTagCompound(tagCompound);
}
}
@Override
public void onWorldJoin() {
if (iModPart.world == null || iModPart.location == null) {
iModPart.setWorld(world());
iModPart.setLocation(new Location(x(), y(), z()));
}
iModPart.onAdded();
}
@Override
public void onWorldSeparate() {
iModPart.onChunkUnload();
}
}

View file

@ -0,0 +1,34 @@
/*
* 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.fmp;
import codechicken.lib.vec.BlockCoord;
import codechicken.lib.vec.Vector3;
import codechicken.multipart.JItemMultiPart;
import codechicken.multipart.MultiPartRegistry;
import codechicken.multipart.TMultiPart;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import techreborn.partSystem.ModPart;
/**
* This item is never added into the game, it is only used to add the part to
* the world.
*/
public class FakeFMPPlacerItem extends JItemMultiPart {
ModPart modPart;
public FakeFMPPlacerItem(ModPart part) {
modPart = part;
}
@Override
public TMultiPart newPart(ItemStack item, EntityPlayer player, World world,
BlockCoord pos, int side, Vector3 vhit) {
TMultiPart w = MultiPartRegistry.createPart(modPart.getName(), false);
return w;
}
}

View file

@ -0,0 +1,29 @@
package techreborn.partSystem.fmp;
import io.netty.buffer.ByteBuf;
import reborncore.common.packets.SimplePacket;
import java.io.IOException;
public class PacketFMPPlacePart extends SimplePacket {
public PacketFMPPlacePart() {
}
@Override
public void writeData(ByteBuf out) throws IOException {
}
@Override
public void readData(ByteBuf in) throws IOException {
}
@Override
public void execute() {
CableConverter.place(player, player.worldObj);
}
}