mirror of
https://github.com/GTNewHorizons/StorageDrawers.git
synced 2026-11-20 04:09:49 +00:00
refactor to use mixin and not forgeeventhandler (still has comments)
This commit is contained in:
1 parent
f0701fbd14
commit
02e108e75d
5 files changed
+116
-64
No files matched your search
@@ -47,7 +47,7 @@ public class BlockCompDrawers extends BlockDrawers implements INetworked {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getDrawerSlot(int side, float hitX, float hitY, float hitZ) {
|
||||
public int getDrawerSlot(int side, float hitX, float hitY, float hitZ) {
|
||||
if (hitTop(hitY)) return 0;
|
||||
|
||||
if (hitLeft(side, hitX, hitZ)) return 1;
|
||||
|
||||
@@ -450,7 +450,7 @@ public class BlockDrawers extends BlockContainer implements IExtendedBlockClickH
|
||||
return false;
|
||||
}
|
||||
|
||||
protected int getDrawerSlot(int side, float hitX, float hitY, float hitZ) {
|
||||
public int getDrawerSlot(int side, float hitX, float hitY, float hitZ) {
|
||||
if (drawerCount == 1) return 0;
|
||||
if (drawerCount == 2) return hitTop(hitY) ? 0 : 1;
|
||||
|
||||
@@ -514,8 +514,6 @@ public class BlockDrawers extends BlockContainer implements IExtendedBlockClickH
|
||||
}
|
||||
|
||||
TileEntityDrawers tileDrawers = getTileEntitySafe(world, x, y, z);
|
||||
tileDrawers.clickedOnPreviousTick = true;
|
||||
Minecraft.getMinecraft().playerController.curBlockDamageMP = 0.0F;
|
||||
|
||||
if (tileDrawers.getDirection() != side) return;
|
||||
|
||||
@@ -523,32 +521,32 @@ public class BlockDrawers extends BlockContainer implements IExtendedBlockClickH
|
||||
|
||||
if (!SecurityManager.hasAccess(player.getGameProfile(), tileDrawers)) return;
|
||||
|
||||
int slot = getDrawerSlot(side, hitX, hitY, hitZ);
|
||||
IDrawer drawer = tileDrawers.getDrawer(slot);
|
||||
if (drawer == null) return;
|
||||
|
||||
final ItemStack item;
|
||||
// if invertSHift is true this will happen when the player is not shifting
|
||||
if (player.isSneaking() != invertShift)
|
||||
item = tileDrawers.takeItemsFromSlot(slot, drawer.getStoredItemStackSize());
|
||||
else item = tileDrawers.takeItemsFromSlot(slot, 1);
|
||||
|
||||
if (StorageDrawers.config.cache.debugTrace)
|
||||
FMLLog.log(StorageDrawers.MOD_ID, Level.INFO, (item == null) ? " null item" : " " + item);
|
||||
|
||||
if (item != null && item.stackSize > 0) {
|
||||
if (!player.inventory.addItemStackToInventory(item)) {
|
||||
ForgeDirection dir = ForgeDirection.getOrientation(side);
|
||||
dropItemStack(world, x + dir.offsetX, y, z + dir.offsetZ, item);
|
||||
world.markBlockForUpdate(x, y, z);
|
||||
} else world.playSoundEffect(
|
||||
x + .5f,
|
||||
y + .5f,
|
||||
z + .5f,
|
||||
"random.pop",
|
||||
.2f,
|
||||
((world.rand.nextFloat() - world.rand.nextFloat()) * .7f + 1) * 2);
|
||||
}
|
||||
// int slot = getDrawerSlot(side, hitX, hitY, hitZ);
|
||||
// IDrawer drawer = tileDrawers.getDrawer(slot);
|
||||
// if (drawer == null) return;
|
||||
//
|
||||
// final ItemStack item;
|
||||
// // if invertSHift is true this will happen when the player is not shifting
|
||||
// if (player.isSneaking() != invertShift)
|
||||
// item = tileDrawers.takeItemsFromSlot(slot, drawer.getStoredItemStackSize());
|
||||
// else item = tileDrawers.takeItemsFromSlot(slot, 1);
|
||||
//
|
||||
// if (StorageDrawers.config.cache.debugTrace)
|
||||
// FMLLog.log(StorageDrawers.MOD_ID, Level.INFO, (item == null) ? " null item" : " " + item);
|
||||
//
|
||||
// if (item != null && item.stackSize > 0) {
|
||||
// if (!player.inventory.addItemStackToInventory(item)) {
|
||||
// ForgeDirection dir = ForgeDirection.getOrientation(side);
|
||||
// dropItemStack(world, x + dir.offsetX, y, z + dir.offsetZ, item);
|
||||
// world.markBlockForUpdate(x, y, z);
|
||||
// } else world.playSoundEffect(
|
||||
// x + .5f,
|
||||
// y + .5f,
|
||||
// z + .5f,
|
||||
// "random.pop",
|
||||
// .2f,
|
||||
// ((world.rand.nextFloat() - world.rand.nextFloat()) * .7f + 1) * 2);
|
||||
// }
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -586,7 +584,7 @@ public class BlockDrawers extends BlockContainer implements IExtendedBlockClickH
|
||||
return side.ordinal() != getTileEntity(world, x, y, z).getDirection();
|
||||
}
|
||||
|
||||
private void dropItemStack(World world, int x, int y, int z, ItemStack stack) {
|
||||
public void dropItemStack(World world, int x, int y, int z, ItemStack stack) {
|
||||
EntityItem entity = new EntityItem(world, x + .5f, y + .5f, z + .5f, stack);
|
||||
entity.addVelocity(-entity.motionX, -entity.motionY, -entity.motionZ);
|
||||
world.spawnEntityInWorld(entity);
|
||||
|
||||
@@ -557,6 +557,9 @@ public abstract class TileEntityDrawers extends BaseTileEntity implements IDrawe
|
||||
ItemStack stack = getItemsFromSlot(slot, count);
|
||||
if (stack == null) return null;
|
||||
|
||||
clickedOnPreviousTick = true;
|
||||
Minecraft.getMinecraft().playerController.curBlockDamageMP = 0.0F;
|
||||
|
||||
int ticksConsecutiveClickRequirement = 50 / (itemsOutputInARow + 5);
|
||||
|
||||
if (ticksClickedInARow < ticksConsecutiveClickRequirement) return null;
|
||||
|
||||
@@ -1,24 +1,82 @@
|
||||
package com.jaquadro.minecraft.storagedrawers.core;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.MovingObjectPosition;
|
||||
import net.minecraft.util.Vec3;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
|
||||
|
||||
import org.apache.logging.log4j.Level;
|
||||
|
||||
import com.jaquadro.minecraft.storagedrawers.StorageDrawers;
|
||||
import com.jaquadro.minecraft.storagedrawers.api.storage.IDrawer;
|
||||
import com.jaquadro.minecraft.storagedrawers.block.BlockDrawers;
|
||||
import com.jaquadro.minecraft.storagedrawers.block.tile.TileEntityDrawers;
|
||||
|
||||
import cpw.mods.fml.common.FMLLog;
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
|
||||
public class ForgeEventHandler {
|
||||
|
||||
@SubscribeEvent
|
||||
public void playerInteracts(PlayerInteractEvent event) {
|
||||
if (event.action == PlayerInteractEvent.Action.LEFT_CLICK_BLOCK
|
||||
&& event.entityPlayer.capabilities.isCreativeMode) {
|
||||
TileEntity tile = event.world.getTileEntity(event.x, event.y, event.z);
|
||||
if (tile instanceof TileEntityDrawers) {
|
||||
int dir = ((TileEntityDrawers) tile).getDirection();
|
||||
if (event.action == PlayerInteractEvent.Action.LEFT_CLICK_BLOCK) {
|
||||
TileEntity mystery_tile = event.world.getTileEntity(event.x, event.y, event.z);
|
||||
if (mystery_tile instanceof TileEntityDrawers tile
|
||||
&& event.world.getBlock(event.x, event.y, event.z) instanceof BlockDrawers block) {
|
||||
int dir = tile.getDirection();
|
||||
if (dir == event.face) {
|
||||
event.setCanceled(true);
|
||||
return;
|
||||
final int reach = 5;
|
||||
double eyeX = event.entityPlayer.posX;
|
||||
double eyeY = event.entityPlayer.posY + event.entityPlayer.getEyeHeight();
|
||||
double eyeZ = event.entityPlayer.posZ;
|
||||
|
||||
Vec3 look = event.entityPlayer.getLookVec();
|
||||
|
||||
Vec3 end = Vec3.createVectorHelper(
|
||||
eyeX + look.xCoord * reach,
|
||||
eyeY + look.yCoord * reach,
|
||||
eyeZ + look.zCoord * reach);
|
||||
|
||||
MovingObjectPosition mop = event.world
|
||||
.rayTraceBlocks(Vec3.createVectorHelper(eyeX, eyeY, eyeZ), end);
|
||||
float hitX = (float) (mop.hitVec.xCoord - mop.blockX);
|
||||
float hitY = (float) (mop.hitVec.yCoord - mop.blockY);
|
||||
float hitZ = (float) (mop.hitVec.zCoord - mop.blockZ);
|
||||
boolean invertShift = StorageDrawers.config.cache.invertShift;
|
||||
|
||||
int slot = block.getDrawerSlot(event.face, hitX, hitY, hitZ);
|
||||
IDrawer drawer = tile.getDrawer(slot);
|
||||
if (drawer == null) return;
|
||||
final ItemStack item;
|
||||
// if invertSHift is true this will happen when the player is not shifting
|
||||
if (event.entityPlayer.isSneaking() != invertShift)
|
||||
item = tile.takeItemsFromSlot(slot, drawer.getStoredItemStackSize());
|
||||
else item = tile.takeItemsFromSlot(slot, 1);
|
||||
|
||||
if (StorageDrawers.config.cache.debugTrace)
|
||||
FMLLog.log(StorageDrawers.MOD_ID, Level.INFO, (item == null) ? " null item" : " " + item);
|
||||
|
||||
if (item != null && item.stackSize > 0) {
|
||||
if (!event.entityPlayer.inventory.addItemStackToInventory(item)) {
|
||||
ForgeDirection dir2 = ForgeDirection.getOrientation(event.face);
|
||||
block.dropItemStack(
|
||||
event.world,
|
||||
event.x + dir2.offsetX,
|
||||
event.y,
|
||||
event.z + dir2.offsetZ,
|
||||
item);
|
||||
event.world.markBlockForUpdate(event.x, event.y, event.z);
|
||||
} else event.world.playSoundEffect(
|
||||
event.x + .5f,
|
||||
event.y + .5f,
|
||||
event.z + .5f,
|
||||
"random.pop",
|
||||
.2f,
|
||||
((event.world.rand.nextFloat() - event.world.rand.nextFloat()) * .7f + 1) * 2);
|
||||
event.setCanceled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+19
-26
@@ -1,36 +1,29 @@
|
||||
package com.jaquadro.minecraft.storagedrawers.mixins.early;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.multiplayer.PlayerControllerMP;
|
||||
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
import com.jaquadro.minecraft.storagedrawers.block.BlockDrawers;
|
||||
import com.jaquadro.minecraft.storagedrawers.block.tile.TileEntityDrawers;
|
||||
|
||||
@Mixin(PlayerControllerMP.class)
|
||||
public abstract class MixinPlayerControllerMP {
|
||||
|
||||
@Shadow
|
||||
private Minecraft mc;
|
||||
|
||||
@Inject(
|
||||
method = "onPlayerDamageBlock",
|
||||
at = @At(
|
||||
value = "INVOKE_ASSIGN",
|
||||
target = "Lnet/minecraft/block/Block;getPlayerRelativeBlockHardness(Lnet/minecraft/entity/player/EntityPlayer;Lnet/minecraft/world/World;III)F"))
|
||||
private void mixin(int x, int y, int z, int side, CallbackInfo ci) { // cancels block break progress and fires a
|
||||
// click
|
||||
// block event on the TileEntityDrawer if applicable
|
||||
if (mc.theWorld.getTileEntity(x, y, z) instanceof TileEntityDrawers ted
|
||||
&& mc.theWorld.getBlock(x, y, z) instanceof BlockDrawers bd) {
|
||||
if (ted.getDirection() == side) {
|
||||
bd.onBlockClicked(mc.theWorld, x, y, z, mc.thePlayer);
|
||||
}
|
||||
}
|
||||
}
|
||||
// @Shadow
|
||||
// private Minecraft mc;
|
||||
//
|
||||
// @Inject(
|
||||
// method = "onPlayerDamageBlock",
|
||||
// at = @At(
|
||||
// value = "INVOKE_ASSIGN",
|
||||
// target =
|
||||
// "Lnet/minecraft/block/Block;getPlayerRelativeBlockHardness(Lnet/minecraft/entity/player/EntityPlayer;Lnet/minecraft/world/World;III)F"))
|
||||
// private void mixin(int x, int y, int z, int side, CallbackInfo ci) { // cancels block break progress and fires a
|
||||
// // click
|
||||
// // block event on the TileEntityDrawer if applicable
|
||||
// if (mc.theWorld.getTileEntity(x, y, z) instanceof TileEntityDrawers ted
|
||||
// && mc.theWorld.getBlock(x, y, z) instanceof BlockDrawers bd) {
|
||||
// if (ted.getDirection() == side) {
|
||||
// bd.onBlockClicked(mc.theWorld, x, y, z, mc.thePlayer);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
}
|
||||
Reference in new issue
Block a user