Multiblock in world transmutation almost done
This commit is contained in:
parent
21020bce90
commit
c6a5774867
6 changed files with 111 additions and 31 deletions
|
@ -1,14 +1,22 @@
|
|||
package com.pahimar.ee3.core.handlers;
|
||||
|
||||
import com.pahimar.ee3.event.ActionEvent;
|
||||
import com.pahimar.ee3.core.helper.TransmutationHelper;
|
||||
import com.pahimar.ee3.event.WorldTransmutationEvent;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.event.ForgeSubscribe;
|
||||
|
||||
public class WorldTransmutationHandler {
|
||||
|
||||
@ForgeSubscribe
|
||||
public void onWorldTransmutationEvent(ActionEvent event) {
|
||||
public void onWorldTransmutationEvent(WorldTransmutationEvent event) {
|
||||
|
||||
System.out.println(event.data);
|
||||
int id = event.world.getBlockId(event.x, event.y, event.z);
|
||||
int meta = event.world.getBlockMetadata(event.x, event.y, event.z);
|
||||
|
||||
if (EquivalencyHandler.instance().areEquivalent(new ItemStack(id, 1, meta), new ItemStack(event.targetID, 1, event.targetMeta))) {
|
||||
TransmutationHelper.transmuteInWorld(event.world, event.player, event.player.getCurrentEquippedItem(), event.x, event.y, event.z, event.targetID, event.targetMeta);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -29,23 +29,12 @@ public class TransmutationHelper {
|
|||
public static ItemStack currentBlockStack = null;
|
||||
public static ItemStack targetBlockStack = null;
|
||||
|
||||
public static boolean transmuteInWorld(World world, EntityPlayer player, ItemStack stack, int x, int y, int z) {
|
||||
public static boolean transmuteInWorld(World world, EntityPlayer player, ItemStack stack, int x, int y, int z, int targetID, int targetMeta) {
|
||||
|
||||
int id = world.getBlockId(x, y, z);
|
||||
int meta = world.getBlockMetadata(x, y, z);
|
||||
|
||||
if ((world.getBlockMaterial(x, y, z) == Material.leaves) && (Block.blocksList[id] instanceof BlockLeaves)) {
|
||||
meta = meta % 4;
|
||||
}
|
||||
|
||||
ItemStack nextItem = getNextBlock(id, meta, player.isSneaking());
|
||||
|
||||
if (nextItem != null) {
|
||||
if (Block.blocksList[nextItem.itemID] != null) {
|
||||
world.setBlockAndMetadataWithNotify(x, y, z, nextItem.itemID, nextItem.getItemDamage());
|
||||
world.playSoundAtEntity(player, Sounds.TRANSMUTE, 0.5F, 1.0F);
|
||||
return true;
|
||||
}
|
||||
if (Block.blocksList[targetID] != null) {
|
||||
world.setBlockAndMetadataWithNotify(x, y, z, targetID, targetMeta);
|
||||
//world.playSoundAtEntity(player, Sounds.TRANSMUTE, 0.5F, 1.0F);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
package com.pahimar.ee3.event;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
|
||||
public class WorldTransmutationEvent extends ActionEvent {
|
||||
|
||||
public int targetID, targetMeta;
|
||||
|
||||
public WorldTransmutationEvent(byte actionType, EntityPlayer player, World world, int x, int y, int z, boolean hasActionOccured, String data) {
|
||||
|
||||
super(actionType, player, world, x, y, z, hasActionOccured, data);
|
||||
targetID = Integer.parseInt(data.substring(0, data.indexOf(":")));
|
||||
targetMeta = Integer.parseInt(data.substring(data.indexOf(":") + 1));
|
||||
}
|
||||
|
||||
}
|
|
@ -70,13 +70,15 @@ public class ItemMiniumStone extends ItemEE
|
|||
@Override
|
||||
public boolean onItemUse(ItemStack itemStack, EntityPlayer entityPlayer, World world, int x, int y, int z, int sideHit, float hitVecX, float hitVecY, float hitVecZ) {
|
||||
|
||||
/*
|
||||
boolean result = TransmutationHelper.transmuteInWorld(world, entityPlayer, itemStack, x, y, z);
|
||||
|
||||
if (result) {
|
||||
itemStack.damageItem(1, entityPlayer);
|
||||
}
|
||||
*/
|
||||
|
||||
return result;
|
||||
return true;
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
|
|
|
@ -21,6 +21,7 @@ import net.minecraft.entity.player.EntityPlayer;
|
|||
import net.minecraft.item.EnumRarity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
|
||||
/**
|
||||
* ItemPhilosopherStone
|
||||
|
@ -83,7 +84,51 @@ public class ItemPhilosopherStone extends ItemEE
|
|||
|
||||
if (!world.isRemote) {
|
||||
if (TransmutationHelper.targetBlockStack != null) {
|
||||
EquivalentExchange3.proxy.sendWorldEventPacket(ActionTypes.TRANSMUTATION, x, y, z, (byte)sideHit, (byte)getCharge(itemStack), (byte)getCharge(itemStack), (byte)getCharge(itemStack), TransmutationHelper.formatTargetBlockInfo(TransmutationHelper.targetBlockStack));
|
||||
int pnX = 1;
|
||||
int pnY = 1;
|
||||
int pnZ = 1;
|
||||
switch (ForgeDirection.getOrientation(sideHit)) {
|
||||
case UP: {
|
||||
pnX = 1 + getCharge(itemStack) * 2;
|
||||
pnZ = 1 + getCharge(itemStack) * 2;
|
||||
break;
|
||||
}
|
||||
case DOWN:{
|
||||
pnX = 1 + getCharge(itemStack) * 2;
|
||||
pnZ = 1 + getCharge(itemStack) * 2;
|
||||
break;
|
||||
}
|
||||
case NORTH:{
|
||||
pnX = 1;
|
||||
pnY = 1;
|
||||
break;
|
||||
}
|
||||
case SOUTH:{
|
||||
pnX = 1 + getCharge(itemStack) * 2;
|
||||
pnY = 1 + getCharge(itemStack) * 2;
|
||||
break;
|
||||
}
|
||||
case EAST:{
|
||||
pnY = 1 + getCharge(itemStack) * 2;
|
||||
pnZ = 1 + getCharge(itemStack) * 2;
|
||||
break;
|
||||
}
|
||||
case WEST:{
|
||||
pnY = 1 + getCharge(itemStack) * 2;
|
||||
pnZ = 1 + getCharge(itemStack) * 2;
|
||||
break;
|
||||
}
|
||||
case UNKNOWN:{
|
||||
pnX = 0;
|
||||
pnY = 0;
|
||||
pnZ = 0;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
EquivalentExchange3.proxy.sendWorldEventPacket(ActionTypes.TRANSMUTATION, x, y, z, (byte)sideHit, (byte)pnX, (byte)pnY, (byte)pnZ, TransmutationHelper.formatTargetBlockInfo(TransmutationHelper.targetBlockStack));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@ import java.io.IOException;
|
|||
|
||||
import com.pahimar.ee3.event.ActionEvent;
|
||||
import com.pahimar.ee3.event.ActionRequestEvent;
|
||||
import com.pahimar.ee3.event.WorldTransmutationEvent;
|
||||
import com.pahimar.ee3.lib.ActionTypes;
|
||||
import com.pahimar.ee3.network.PacketTypeHandler;
|
||||
|
||||
|
@ -54,8 +55,9 @@ public class PacketRequestEvent extends PacketEE {
|
|||
this.originY = originY;
|
||||
this.originZ = originZ;
|
||||
}
|
||||
|
||||
|
||||
public void setSideHit(byte sideHit) {
|
||||
|
||||
this.sideHit = sideHit;
|
||||
}
|
||||
|
||||
|
@ -101,17 +103,33 @@ public class PacketRequestEvent extends PacketEE {
|
|||
|
||||
EntityPlayer thePlayer = (EntityPlayer) player;
|
||||
ActionRequestEvent actionRequestEvent = null;
|
||||
ActionEvent actionEvent = new ActionEvent(ActionTypes.TRANSMUTATION, thePlayer, thePlayer.worldObj, originX, originY, originZ, false, data);
|
||||
|
||||
if (actionEvent != null) {
|
||||
actionRequestEvent = new ActionRequestEvent(thePlayer, actionEvent, originX, originY, originZ, (int) sideHit);
|
||||
MinecraftForge.EVENT_BUS.post(actionRequestEvent);
|
||||
|
||||
if (actionRequestEvent.allowEvent != Result.DENY) {
|
||||
MinecraftForge.EVENT_BUS.post(actionEvent);
|
||||
ActionEvent actionEvent = null;
|
||||
|
||||
int lowerBoundX = -1 * rangeX / 2;
|
||||
int upperBoundX = -1 * lowerBoundX;
|
||||
int lowerBoundY = -1 * rangeY / 2;
|
||||
int upperBoundY = -1 * lowerBoundY;
|
||||
int lowerBoundZ = -1 * rangeZ / 2;
|
||||
int upperBoundZ = -1 * lowerBoundZ;
|
||||
|
||||
for (int x = lowerBoundX; x <= upperBoundX; x++) {
|
||||
for (int y = lowerBoundY; y <= upperBoundY; y++) {
|
||||
for (int z = lowerBoundZ; z <= upperBoundZ; z++) {
|
||||
|
||||
actionEvent = new WorldTransmutationEvent(ActionTypes.TRANSMUTATION, thePlayer, thePlayer.worldObj, originX + x, originY + y, originZ + z, false, data);
|
||||
|
||||
if (actionEvent != null) {
|
||||
actionRequestEvent = new ActionRequestEvent(thePlayer, actionEvent, originX + x, originY + y, originZ + z, (int) sideHit);
|
||||
MinecraftForge.EVENT_BUS.post(actionRequestEvent);
|
||||
|
||||
if (actionRequestEvent.allowEvent != Result.DENY) {
|
||||
MinecraftForge.EVENT_BUS.post(actionEvent);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue