Cables can now be placed inside existing multiparts
This commit is contained in:
parent
88f4737772
commit
269c97497f
5 changed files with 77 additions and 75 deletions
|
@ -17,6 +17,7 @@ import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.entity.player.EntityPlayerMP;
|
import net.minecraft.entity.player.EntityPlayerMP;
|
||||||
import net.minecraft.network.INetHandler;
|
import net.minecraft.network.INetHandler;
|
||||||
import net.minecraft.network.NetHandlerPlayServer;
|
import net.minecraft.network.NetHandlerPlayServer;
|
||||||
|
import techreborn.partSystem.fmp.PacketFMPPlacePart;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
|
@ -118,6 +119,7 @@ public class PacketPipeline extends MessageToMessageCodec<FMLProxyPacket, Abstra
|
||||||
|
|
||||||
private void registerPackets() {
|
private void registerPackets() {
|
||||||
registerPacket(PacketIdsu.class);
|
registerPacket(PacketIdsu.class);
|
||||||
|
registerPacket(PacketFMPPlacePart.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Method to call from FMLPostInitializationEvent
|
// Method to call from FMLPostInitializationEvent
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package techreborn.partSystem.parts;
|
package techreborn.partSystem.fmp;
|
||||||
|
|
||||||
import codechicken.lib.packet.PacketCustom;
|
import codechicken.lib.packet.PacketCustom;
|
||||||
import codechicken.lib.raytracer.RayTracer;
|
import codechicken.lib.raytracer.RayTracer;
|
||||||
|
@ -7,8 +7,6 @@ import codechicken.lib.vec.Vector3;
|
||||||
import codechicken.multipart.MultiPartRegistry;
|
import codechicken.multipart.MultiPartRegistry;
|
||||||
import codechicken.multipart.TMultiPart;
|
import codechicken.multipart.TMultiPart;
|
||||||
import codechicken.multipart.TileMultipart;
|
import codechicken.multipart.TileMultipart;
|
||||||
import codechicken.multipart.minecraft.McBlockPart;
|
|
||||||
import codechicken.multipart.minecraft.McMultipartSPH;
|
|
||||||
import cpw.mods.fml.common.eventhandler.EventPriority;
|
import cpw.mods.fml.common.eventhandler.EventPriority;
|
||||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||||
import ic2.api.item.IC2Items;
|
import ic2.api.item.IC2Items;
|
||||||
|
@ -25,10 +23,10 @@ import net.minecraft.tileentity.TileEntity;
|
||||||
import net.minecraft.util.MovingObjectPosition;
|
import net.minecraft.util.MovingObjectPosition;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import net.minecraftforge.common.MinecraftForge;
|
import net.minecraftforge.common.MinecraftForge;
|
||||||
import net.minecraftforge.common.util.ForgeDirection;
|
|
||||||
import net.minecraftforge.event.entity.player.PlayerDestroyItemEvent;
|
import net.minecraftforge.event.entity.player.PlayerDestroyItemEvent;
|
||||||
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
|
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
|
||||||
import techreborn.partSystem.fmp.FMPModPart;
|
import techreborn.Core;
|
||||||
|
import techreborn.partSystem.parts.CablePart;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
@ -54,106 +52,78 @@ public class CableConverter implements MultiPartRegistry.IPartConverter {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private ThreadLocal<Object> placing = new ThreadLocal<Object>();
|
private final ThreadLocal<Object> placing = new ThreadLocal<Object>();
|
||||||
|
|
||||||
@SubscribeEvent(priority = EventPriority.LOW)
|
@SubscribeEvent(priority = EventPriority.LOW)
|
||||||
public void playerInteract(PlayerInteractEvent event)
|
public void playerInteract(PlayerInteractEvent event) {
|
||||||
{
|
if (event.action == PlayerInteractEvent.Action.RIGHT_CLICK_BLOCK && event.entityPlayer.worldObj.isRemote) {
|
||||||
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
|
||||||
{
|
|
||||||
if(placing.get() != null)
|
|
||||||
return;
|
|
||||||
placing.set(event);
|
placing.set(event);
|
||||||
if(place(event.entityPlayer, event.entityPlayer.worldObj))
|
if (place(event.entityPlayer, event.entityPlayer.worldObj)) event.setCanceled(true);
|
||||||
event.setCanceled(true);
|
|
||||||
placing.set(null);
|
placing.set(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean place(EntityPlayer player, World world)
|
public static boolean place(EntityPlayer player, World world) {
|
||||||
{
|
|
||||||
MovingObjectPosition hit = RayTracer.reTrace(world, player);
|
MovingObjectPosition hit = RayTracer.reTrace(world, player);
|
||||||
if(hit == null)
|
if (hit == null) return false;
|
||||||
return false;
|
|
||||||
|
|
||||||
BlockCoord pos = new BlockCoord(hit.blockX, hit.blockY, hit.blockZ).offset(hit.sideHit);
|
BlockCoord pos = new BlockCoord(hit.blockX, hit.blockY, hit.blockZ);
|
||||||
ItemStack held = player.getHeldItem();
|
ItemStack held = player.getHeldItem();
|
||||||
|
|
||||||
FMPModPart part = null;
|
FMPModPart part = null;
|
||||||
if(held == null)
|
if (held == null) return false;
|
||||||
return false;
|
|
||||||
|
|
||||||
Item heldItem = held.getItem();
|
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(heldItem == IC2Items.getItem("copperCableItem").getItem())
|
|
||||||
part = placeCable(world, pos, hit.sideHit, held);
|
|
||||||
|
|
||||||
if(part == null)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (world.isRemote && !player.isSneaking())//attempt to use block activated like normal and tell the server the right stuff
|
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);
|
Vector3 f = new Vector3(hit.hitVec).add(-hit.blockX, -hit.blockY, -hit.blockZ);
|
||||||
Block block = world.getBlock(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))
|
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();
|
player.swingItem();
|
||||||
PacketCustom.sendToServer(new C08PacketPlayerBlockPlacement(
|
PacketCustom.sendToServer(new C08PacketPlayerBlockPlacement(hit.blockX, hit.blockY, hit.blockZ, hit.sideHit, player.inventory.getCurrentItem(), (float) f.x, (float) f.y, (float) f.z));
|
||||||
hit.blockX, hit.blockY, hit.blockZ, hit.sideHit,
|
|
||||||
player.inventory.getCurrentItem(),
|
|
||||||
(float) f.x, (float) f.y, (float) f.z));
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TileMultipart tile = TileMultipart.getOrConvertTile(world, pos);
|
TileMultipart tile = TileMultipart.getOrConvertTile(world, pos);
|
||||||
if(tile == null || !tile.canAddPart(part))
|
if (tile == null || !tile.canAddPart(part)) {
|
||||||
return false;
|
pos = pos.offset(hit.sideHit);
|
||||||
|
tile = TileMultipart.getOrConvertTile(world, pos);
|
||||||
|
if (tile == null || !tile.canAddPart(part)) return false;
|
||||||
|
}
|
||||||
|
|
||||||
if(!world.isRemote)
|
if (!world.isRemote) {
|
||||||
{
|
|
||||||
TileMultipart.addPart(world, pos, part);
|
TileMultipart.addPart(world, pos, part);
|
||||||
world.playSoundEffect(pos.x + 0.5, pos.y + 0.5, pos.z + 0.5,
|
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);
|
||||||
Blocks.wool.stepSound.func_150496_b(),
|
if (!player.capabilities.isCreativeMode) {
|
||||||
(Blocks.wool.stepSound.getVolume() + 1.0F) / 2.0F,
|
|
||||||
Blocks.wool.stepSound.getPitch() * 0.8F);
|
|
||||||
if(!player.capabilities.isCreativeMode)
|
|
||||||
{
|
|
||||||
held.stackSize--;
|
held.stackSize--;
|
||||||
if (held.stackSize == 0)
|
if (held.stackSize == 0) {
|
||||||
{
|
|
||||||
player.inventory.mainInventory[player.inventory.currentItem] = null;
|
player.inventory.mainInventory[player.inventory.currentItem] = null;
|
||||||
MinecraftForge.EVENT_BUS.post(new PlayerDestroyItemEvent(player, held));
|
MinecraftForge.EVENT_BUS.post(new PlayerDestroyItemEvent(player, held));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
player.swingItem();
|
player.swingItem();
|
||||||
// new PacketCustom(McMultipartSPH.channel, 1).sendToServer();
|
Core.packetPipeline.sendToServer(new PacketFMPPlacePart());
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean ignoreActivate(Block block)
|
/**
|
||||||
{
|
* Because vanilla is weird.
|
||||||
if(block instanceof BlockFence)
|
*/
|
||||||
return true;
|
private static boolean ignoreActivate(Block block) {
|
||||||
|
if (block instanceof BlockFence) return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static FMPModPart placeCable(World world, BlockCoord pos, int side, ItemStack held)
|
|
||||||
{
|
|
||||||
if(side == 0)
|
|
||||||
return null;
|
|
||||||
pos = pos.copy().offset(side^1);
|
|
||||||
Block block = world.getBlock(pos.x, pos.y, pos.z);
|
|
||||||
if(!block.isSideSolid(world, pos.x, pos.y, pos.z, ForgeDirection.getOrientation(side)) && (side != 1 || block.canPlaceTorchOnTop(world, pos.x, pos.y, pos.z)))
|
|
||||||
return null;
|
|
||||||
|
|
||||||
CablePart part = new CablePart();
|
|
||||||
part.setType(held.getItemDamage() * 16);
|
|
||||||
return new FMPModPart(part);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -12,7 +12,6 @@ import codechicken.multipart.NormallyOccludedPart;
|
||||||
import codechicken.multipart.TMultiPart;
|
import codechicken.multipart.TMultiPart;
|
||||||
import codechicken.multipart.TileMultipart;
|
import codechicken.multipart.TileMultipart;
|
||||||
import cpw.mods.fml.common.Loader;
|
import cpw.mods.fml.common.Loader;
|
||||||
import ic2.api.info.IC2Classic;
|
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
|
@ -25,7 +24,6 @@ import techreborn.partSystem.IModPart;
|
||||||
import techreborn.partSystem.IPartProvider;
|
import techreborn.partSystem.IPartProvider;
|
||||||
import techreborn.partSystem.ModPart;
|
import techreborn.partSystem.ModPart;
|
||||||
import techreborn.partSystem.ModPartRegistry;
|
import techreborn.partSystem.ModPartRegistry;
|
||||||
import techreborn.partSystem.parts.CableConverter;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
|
|
@ -16,10 +16,8 @@ import codechicken.multipart.TMultiPart;
|
||||||
import codechicken.multipart.TSlottedPart;
|
import codechicken.multipart.TSlottedPart;
|
||||||
import cpw.mods.fml.relauncher.Side;
|
import cpw.mods.fml.relauncher.Side;
|
||||||
import cpw.mods.fml.relauncher.SideOnly;
|
import cpw.mods.fml.relauncher.SideOnly;
|
||||||
import net.minecraft.entity.Entity;
|
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraft.util.AxisAlignedBB;
|
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import techreborn.lib.Location;
|
import techreborn.lib.Location;
|
||||||
import techreborn.lib.vecmath.Vecs3d;
|
import techreborn.lib.vecmath.Vecs3d;
|
||||||
|
|
|
@ -0,0 +1,34 @@
|
||||||
|
package techreborn.partSystem.fmp;
|
||||||
|
|
||||||
|
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
|
import techreborn.packets.AbstractPacket;
|
||||||
|
|
||||||
|
public class PacketFMPPlacePart extends AbstractPacket {
|
||||||
|
|
||||||
|
|
||||||
|
public PacketFMPPlacePart() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void encodeInto(ChannelHandlerContext ctx, ByteBuf buffer) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void decodeInto(ChannelHandlerContext ctx, ByteBuf buffer) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handleClientSide(EntityPlayer player) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handleServerSide(EntityPlayer player) {
|
||||||
|
CableConverter.place(player, player.worldObj);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue