Fixed serverside issues. Hidden randomizer bag. New issue: build does not work with messages.

This commit is contained in:
Christian Knaapen
2018-09-22 00:09:52 +02:00
parent bf258580d4
commit cb006c4983
12 changed files with 183 additions and 94 deletions

View File

@@ -1,10 +1,17 @@
package nl.requios.effortlessbuilding;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3i;
import net.minecraftforge.common.util.BlockSnapshot;
import net.minecraft.world.World;
import net.minecraftforge.event.world.BlockEvent;
import net.minecraftforge.items.IItemHandler;
import nl.requios.effortlessbuilding.item.ItemRandomizerBag;
public class Array {
//TODO config file
@@ -37,14 +44,33 @@ public class Array {
BlockPos pos = event.getPos();
Vec3i offset = new Vec3i(a.offset.getX(), a.offset.getY(), a.offset.getZ());
//Randomizer bag synergy
IItemHandler bagInventory = null;
if (event.getPlayer().getHeldItemMainhand().getItem() instanceof ItemRandomizerBag) {
bagInventory = ItemRandomizerBag.getBagInventory(event.getPlayer().getHeldItemMainhand());
//EffortlessBuilding.log(event.getPlayer(), "placed with bag");
}
//EffortlessBuilding.log(event.getPlayer(), event.getPlayer().getHeldItem(event.getHand()).getDisplayName());
//TODO fix not recognizing its the bag in singleplayer and now in multiplayer too?
for (int i = 0; i < a.count; i++) {
pos = pos.add(offset);
if (event.getWorld().isBlockLoaded(pos, true)) {
event.getWorld().setBlockState(pos, event.getPlacedBlock());
IBlockState blockState = bagInventory == null ? event.getPlacedBlock() :
getBlockStateFromRandomizerBag(bagInventory, event.getWorld(), event.getPlayer(), event.getPos());
event.getWorld().setBlockState(pos, blockState);
}
}
}
private static IBlockState getBlockStateFromRandomizerBag(IItemHandler bagInventory, World world, EntityPlayer player, BlockPos pos) {
int randomSlot = ItemRandomizerBag.pickRandomSlot(bagInventory);
ItemStack stack = bagInventory.getStackInSlot(randomSlot);
//TODO get facing from getPlacedAgainst and getPlacedBlock
return Block.getBlockFromItem(stack.getItem()).getStateForPlacement(world, pos, EnumFacing.NORTH, 0, 0, 0, stack.getMetadata(), player, EnumHand.MAIN_HAND);
}
//Called from EventHandler
public static void onBlockBroken(BlockEvent.BreakEvent event) {
if (event.getWorld().isRemote) return;

View File

@@ -29,7 +29,7 @@ public class EffortlessBuilding
{
public static final String MODID = "effortlessbuilding";
public static final String NAME = "Effortless Building";
public static final String VERSION = "0.1.2";
public static final String VERSION = "0.1.3";
@Mod.Instance(EffortlessBuilding.MODID)
public static EffortlessBuilding instance;
@@ -44,11 +44,13 @@ public class EffortlessBuilding
public static final SimpleNetworkWrapper packetHandler = NetworkRegistry.INSTANCE.newSimpleChannel(EffortlessBuilding.MODID);
public static final ItemRandomizerBag ITEM_RANDOMIZER_BAG = new ItemRandomizerBag();
public static final Block[] BLOCKS = {
};
public static final Item[] ITEMS = {
new ItemRandomizerBag()
ITEM_RANDOMIZER_BAG
};
public static final int RANDOMIZER_BAG_GUI = 0;

View File

@@ -6,6 +6,7 @@ import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.util.EnumHand;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.event.AttachCapabilitiesEvent;
import net.minecraftforge.event.RegistryEvent;

View File

@@ -1,15 +1,16 @@
package nl.requios.effortlessbuilding;
import net.minecraft.block.Block;
import net.minecraft.block.BlockDirectional;
import net.minecraft.block.BlockDispenser;
import net.minecraft.block.BlockStairs;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.EntityPlayerSP;
import net.minecraft.client.renderer.BufferBuilder;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos;
@@ -22,6 +23,8 @@ import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import net.minecraftforge.items.IItemHandler;
import nl.requios.effortlessbuilding.item.ItemRandomizerBag;
import org.lwjgl.opengl.GL11;
import org.lwjgl.util.Color;
@@ -76,65 +79,87 @@ public class Mirror {
if (oldBlockPos.getX() + 0.5 < m.position.x - m.radius || oldBlockPos.getX() + 0.5 > m.position.x + m.radius ||
oldBlockPos.getY() + 0.5 < m.position.y - m.radius || oldBlockPos.getY() + 0.5 > m.position.y + m.radius ||
oldBlockPos.getZ() + 0.5 < m.position.z - m.radius || oldBlockPos.getZ() + 0.5 > m.position.z+ m.radius)
oldBlockPos.getZ() + 0.5 < m.position.z - m.radius || oldBlockPos.getZ() + 0.5 > m.position.z + m.radius)
return;
//Randomizer bag synergy
IItemHandler bagInventory = null;
if (event.getPlayer().getHeldItem(event.getHand()).getItem() == EffortlessBuilding.ITEM_RANDOMIZER_BAG) {
bagInventory = ItemRandomizerBag.getBagInventory(event.getPlayer().getHeldItem(EnumHand.MAIN_HAND));
}
if (m.mirrorX) {
placeMirrorX(event.getWorld(), event.getPlayer(), m, oldBlockPos, event.getPlacedBlock());
placeMirrorX(event.getWorld(), event.getPlayer(), m, event.getPos(), event.getPlacedBlock(), bagInventory);
}
if (m.mirrorY) {
placeMirrorY(event.getWorld(), event.getPlayer(), m, oldBlockPos, event.getPlacedBlock());
placeMirrorY(event.getWorld(), event.getPlayer(), m, oldBlockPos, event.getPlacedBlock(), bagInventory);
}
if (m.mirrorZ) {
placeMirrorZ(event.getWorld(), event.getPlayer(), m, oldBlockPos, event.getPlacedBlock());
placeMirrorZ(event.getWorld(), event.getPlayer(), m, oldBlockPos, event.getPlacedBlock(), bagInventory);
}
}
private static void placeMirrorX(World world, EntityPlayer player, MirrorSettings m, BlockPos oldBlockPos, IBlockState oldBlockState) {
private static IBlockState getBlockStateFromRandomizerBag(IItemHandler bagInventory, World world, EntityPlayer player, BlockPos pos) {
int randomSlot = ItemRandomizerBag.pickRandomSlot(bagInventory);
ItemStack stack = bagInventory.getStackInSlot(randomSlot);
//TODO get facing from getPlacedAgainst and getPlacedBlock
return Block.getBlockFromItem(stack.getItem()).getStateForPlacement(world, pos, EnumFacing.NORTH, 0, 0, 0, stack.getMetadata(), player, EnumHand.MAIN_HAND);
}
private static void placeMirrorX(World world, EntityPlayer player, MirrorSettings m, BlockPos oldBlockPos, IBlockState oldBlockState, IItemHandler bagInventory) {
//find mirror position
double x = m.position.x + (m.position.x - oldBlockPos.getX() - 0.5);
BlockPos newBlockPos = new BlockPos(x, oldBlockPos.getY(), oldBlockPos.getZ());
IBlockState newBlockState = oldBlockState;
//Randomizer bag synergy
if (bagInventory != null)
oldBlockState = getBlockStateFromRandomizerBag(bagInventory, world, player, oldBlockPos);
IBlockState newBlockState = oldBlockState.withMirror(net.minecraft.util.Mirror.FRONT_BACK);
//place block
if (world.isBlockLoaded(newBlockPos, true)) {
newBlockState = oldBlockState.withMirror(net.minecraft.util.Mirror.FRONT_BACK);
placeBlock(world, player, newBlockPos, newBlockState);
}
if (m.mirrorY) placeMirrorY(world, player, m, newBlockPos, newBlockState);
if (m.mirrorZ) placeMirrorZ(world, player, m, newBlockPos, newBlockState);
if (m.mirrorY) placeMirrorY(world, player, m, newBlockPos, newBlockState, bagInventory);
if (m.mirrorZ) placeMirrorZ(world, player, m, newBlockPos, newBlockState, bagInventory);
}
private static void placeMirrorY(World world, EntityPlayer player, MirrorSettings m, BlockPos oldBlockPos, IBlockState oldBlockState) {
private static void placeMirrorY(World world, EntityPlayer player, MirrorSettings m, BlockPos oldBlockPos, IBlockState oldBlockState, IItemHandler bagInventory) {
//find mirror position
double y = m.position.y + (m.position.y - oldBlockPos.getY() - 0.5);
BlockPos newBlockPos = new BlockPos(oldBlockPos.getX(), y, oldBlockPos.getZ());
IBlockState newBlockState = oldBlockState;
//Randomizer bag synergy
if (bagInventory != null)
oldBlockState = getBlockStateFromRandomizerBag(bagInventory, world, player, oldBlockPos);
IBlockState newBlockState = getVerticalMirror(oldBlockState);
//place block
if (world.isBlockLoaded(newBlockPos, true)) {
newBlockState = getVerticalMirror(oldBlockState);
placeBlock(world, player, newBlockPos, newBlockState);
}
if (m.mirrorZ) placeMirrorZ(world, player, m, newBlockPos, newBlockState);
if (m.mirrorZ) placeMirrorZ(world, player, m, newBlockPos, newBlockState, bagInventory);
}
private static void placeMirrorZ(World world, EntityPlayer player, MirrorSettings m, BlockPos oldBlockPos, IBlockState oldBlockState) {
private static void placeMirrorZ(World world, EntityPlayer player, MirrorSettings m, BlockPos oldBlockPos, IBlockState oldBlockState, IItemHandler bagInventory) {
//find mirror position
double z = m.position.z + (m.position.z - oldBlockPos.getZ() - 0.5);
BlockPos newBlockPos = new BlockPos(oldBlockPos.getX(), oldBlockPos.getY(), z);
IBlockState newBlockState = oldBlockState;
//Randomizer bag synergy
if (bagInventory != null)
oldBlockState = getBlockStateFromRandomizerBag(bagInventory, world, player, oldBlockPos);
IBlockState newBlockState = oldBlockState.withMirror(net.minecraft.util.Mirror.LEFT_RIGHT);
//place block
if (world.isBlockLoaded(newBlockPos, true)) {
newBlockState = oldBlockState.withMirror(net.minecraft.util.Mirror.LEFT_RIGHT);
placeBlock(world, player, newBlockPos, newBlockState);
}
}
private static void placeBlock(World world, EntityPlayer player, BlockPos newBlockPos, IBlockState newBlockState){
private static void placeBlock(World world, EntityPlayer player, BlockPos newBlockPos, IBlockState newBlockState) {
world.setBlockState(newBlockPos, newBlockState);
//Array synergy
@@ -189,7 +214,7 @@ public class Mirror {
if (oldBlockPos.getX() + 0.5 < m.position.x - m.radius || oldBlockPos.getX() + 0.5 > m.position.x + m.radius ||
oldBlockPos.getY() + 0.5 < m.position.y - m.radius || oldBlockPos.getY() + 0.5 > m.position.y + m.radius ||
oldBlockPos.getZ() + 0.5 < m.position.z - m.radius || oldBlockPos.getZ() + 0.5 > m.position.z+ m.radius)
oldBlockPos.getZ() + 0.5 < m.position.z - m.radius || oldBlockPos.getZ() + 0.5 > m.position.z + m.radius)
return;
if (m.mirrorX) {
@@ -238,7 +263,7 @@ public class Mirror {
}
}
private static void breakBlock(BlockEvent.BreakEvent event, BlockPos newBlockPos){
private static void breakBlock(BlockEvent.BreakEvent event, BlockPos newBlockPos) {
event.getWorld().setBlockToAir(newBlockPos);
//Array synergy
@@ -249,7 +274,7 @@ public class Mirror {
@SubscribeEvent
@SideOnly(Side.CLIENT)
public static void onRender(RenderWorldLastEvent event) {
EntityPlayerSP player = Minecraft.getMinecraft().player;
EntityPlayer player = Minecraft.getMinecraft().player;
BuildSettingsManager.BuildSettings buildSettings = BuildSettingsManager.getBuildSettings(player);
if (buildSettings == null) return;
MirrorSettings m = buildSettings.getMirrorSettings();

View File

@@ -1,17 +1,14 @@
package nl.requios.effortlessbuilding.item;
import net.minecraft.block.Block;
import net.minecraft.block.SoundType;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.*;
import net.minecraft.util.ActionResult;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.common.capabilities.ICapabilityProvider;
@@ -28,15 +25,14 @@ import java.util.Random;
public class ItemRandomizerBag extends Item {
public static final int INV_SIZE = 5;
private Random rand;
private static Random rand = new Random(1337);
public ItemRandomizerBag() {
this.setRegistryName(EffortlessBuilding.MODID, "randomizer_bag");
this.setUnlocalizedName(this.getRegistryName().toString());
this.maxStackSize = 1;
this.setCreativeTab(CreativeTabs.DECORATIONS);
rand = new Random(1337);
//this.setCreativeTab(CreativeTabs.DECORATIONS); //TODO add back in
}
@Override
@@ -47,22 +43,73 @@ public class ItemRandomizerBag extends Item {
//Open inventory
player.openGui(EffortlessBuilding.instance, EffortlessBuilding.RANDOMIZER_BAG_GUI, world, 0, 0, 0);
} else {
//Place block
return placeRandomBlockFromBag(player, world, pos, hand, facing, hitX, hitY, hitZ);
//Use item
//Get bag inventory
ItemStack bag = player.getHeldItem(hand);
IItemHandler bagInventory = getBagInventory(bag);
if (bagInventory == null)
return EnumActionResult.FAIL;
int randomSlot = pickRandomSlot(bagInventory);
if (randomSlot < 0 || randomSlot > bagInventory.getSlots()) return EnumActionResult.FAIL;
ItemStack toPlace = bagInventory.getStackInSlot(randomSlot);
if (toPlace.isEmpty()) return EnumActionResult.FAIL;
bag.setItemDamage(toPlace.getMetadata());
return toPlace.onItemUse(player, world, pos, hand, facing, hitX, hitY, hitZ);
}
return EnumActionResult.SUCCESS;
}
private EnumActionResult placeRandomBlockFromBag(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ){
@Override
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand) {
if (player.isSneaking()) {
if (world.isRemote) return new ActionResult<>(EnumActionResult.SUCCESS, player.getHeldItem(hand));
//Open inventory
player.openGui(EffortlessBuilding.instance, EffortlessBuilding.RANDOMIZER_BAG_GUI, world, 0, 0, 0);
} else {
//Use item
//Get bag inventory
ItemStack bag = player.getHeldItem(hand);
if (!bag.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null)) return EnumActionResult.FAIL;
IItemHandler bagInventory = bag.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
IItemHandler bagInventory = getBagInventory(bag);
if (bagInventory == null)
return new ActionResult<>(EnumActionResult.FAIL, player.getHeldItem(hand));
int randomSlot = pickRandomSlot(bagInventory);
if (randomSlot < 0 || randomSlot > bagInventory.getSlots())
return new ActionResult<>(EnumActionResult.FAIL, player.getHeldItem(hand));
ItemStack toUse = bagInventory.getStackInSlot(randomSlot);
if (toUse.isEmpty()) return new ActionResult<>(EnumActionResult.FAIL, player.getHeldItem(hand));
return toUse.useItemRightClick(world, player, hand);
}
return new ActionResult<>(EnumActionResult.PASS, player.getHeldItem(hand));
}
/**
* Get the inventory of a randomizer bag by checking the capability.
* @param bag
* @return
*/
public static IItemHandler getBagInventory(ItemStack bag) {
if (!bag.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null)) return null;
return bag.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
}
/**
* Pick a random slot from the bag. Empty slots will never get chosen.
* @param bagInventory
* @return
*/
public static int pickRandomSlot(IItemHandler bagInventory) {
//Find how many stacks are non-empty, and save them in a list
int nonempty = 0;
List<ItemStack> nonEmptyStacks = new ArrayList<>(5);
List<Integer> originalSlots = new ArrayList<>(5);
List<ItemStack> nonEmptyStacks = new ArrayList<>(INV_SIZE);
List<Integer> originalSlots = new ArrayList<>(INV_SIZE);
for (int i = 0; i < bagInventory.getSlots(); i++) {
ItemStack stack = bagInventory.getStackInSlot(i);
if (!stack.isEmpty()) {
@@ -72,51 +119,15 @@ public class ItemRandomizerBag extends Item {
}
}
if (nonEmptyStacks.size() != originalSlots.size()) throw new Error("NonEmptyStacks and OriginalSlots not same size");
if (nonEmptyStacks.size() != originalSlots.size())
throw new Error("NonEmptyStacks and OriginalSlots not same size");
if (nonempty == 0) return EnumActionResult.FAIL;
if (nonempty == 0) return -1;
//Pick random slot
int randomSlot = rand.nextInt(nonempty);
ItemStack toPlace = nonEmptyStacks.get(randomSlot);
if (toPlace.isEmpty()) return EnumActionResult.FAIL;
if (toPlace.getItem() instanceof ItemBlock) {
IBlockState existingBlockState = world.getBlockState(pos);
Block existingBlock = existingBlockState.getBlock();
if (!existingBlock.isReplaceable(world, pos))
{
pos = pos.offset(facing);
}
Block block = Block.getBlockFromItem(toPlace.getItem());
if (!toPlace.isEmpty() && player.canPlayerEdit(pos, facing, toPlace) && world.mayPlace(block, pos, false, facing, (Entity)null)) {
IBlockState blockState = block.getStateForPlacement(world, pos, facing, hitX, hitY, hitZ, toPlace.getMetadata(), player, hand);
if (world.setBlockState(pos, blockState)){
SoundType soundType = block.getSoundType(blockState, world, pos, player);
world.playSound(player, pos, soundType.getPlaceSound(), SoundCategory.BLOCKS, (soundType.getVolume() + 1.0F) / 2.0F, soundType.getPitch() * 0.8F);
if (!player.isCreative())
bagInventory.extractItem(originalSlots.get(randomSlot), 1, false);
}
//((ItemBlock) toPlace.getItem()).placeBlockAt(toPlace, player, world, pos, facing, hitX, hitY, hitZ, blockState);
//return ((ItemBlock) toPlace.getItem()).onItemUse(player, world, pos, hand, facing, hitX, hitY, hitZ);
}
}
return EnumActionResult.SUCCESS;
}
@Override
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand) {
if (world.isRemote) return new ActionResult<>(EnumActionResult.PASS, player.getHeldItem(hand));
//Open inventory
player.openGui(EffortlessBuilding.instance, EffortlessBuilding.RANDOMIZER_BAG_GUI, world, 0, 0, 0);
return new ActionResult<>(EnumActionResult.PASS, player.getHeldItem(hand));
return originalSlots.get(randomSlot);
}
@Override

View File

@@ -13,6 +13,7 @@ import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
import nl.requios.effortlessbuilding.Array;
import nl.requios.effortlessbuilding.BuildSettingsManager;
import nl.requios.effortlessbuilding.BuildSettingsManager.BuildSettings;
import nl.requios.effortlessbuilding.EffortlessBuilding;
import nl.requios.effortlessbuilding.Mirror;
public class BuildSettingsMessage implements IMessage {
@@ -84,7 +85,7 @@ public class BuildSettingsMessage implements IMessage {
//EffortlessBuilding.log("message received on " + ctx.side + " side");
// This is the player the packet was sent to the server from
EntityPlayer player = (ctx.side.isClient() ? Minecraft.getMinecraft().player : ctx.getServerHandler().player);
EntityPlayer player = EffortlessBuilding.proxy.getPlayerEntityFromContext(ctx);
// The value that was sent
BuildSettings buildSettings = message.buildSettings;
Mirror.MirrorSettings m = buildSettings.getMirrorSettings();
@@ -98,9 +99,9 @@ public class BuildSettingsMessage implements IMessage {
a.count = Math.max(0, a.count);
// Execute the action on the main server thread by adding it as a scheduled task
IThreadListener threadListener = (ctx.side.isClient() ? Minecraft.getMinecraft() : ((EntityPlayerMP) player).getServerWorld());
IThreadListener threadListener = EffortlessBuilding.proxy.getThreadListenerFromContext(ctx);
threadListener.addScheduledTask(() -> {
EntityPlayer p = (ctx.side.isClient() ? Minecraft.getMinecraft().player : ctx.getServerHandler().player);
EntityPlayer p = EffortlessBuilding.proxy.getPlayerEntityFromContext(ctx);
BuildSettingsManager.setBuildSettings(p, buildSettings);
});
// No response packet

View File

@@ -8,6 +8,7 @@ import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
import net.minecraftforge.fml.relauncher.Side;
import nl.requios.effortlessbuilding.EffortlessBuilding;
import nl.requios.effortlessbuilding.QuickReplace;
import nl.requios.effortlessbuilding.proxy.ClientProxy;
@@ -77,7 +78,7 @@ public class QuickReplaceMessage implements IMessage {
} else {
//Received serverside
ctx.getServerHandler().player.getServerWorld().addScheduledTask(() -> {
EffortlessBuilding.proxy.getThreadListenerFromContext(ctx).addScheduledTask(() -> {
QuickReplace.onMessageReceived(ctx.getServerHandler().player, message);
});
}

View File

@@ -7,6 +7,7 @@ import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.client.settings.KeyBinding;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.util.IThreadListener;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.util.text.TextFormatting;
import net.minecraftforge.client.event.ModelRegistryEvent;
@@ -24,6 +25,7 @@ import nl.requios.effortlessbuilding.BuildSettingsManager;
import nl.requios.effortlessbuilding.EffortlessBuilding;
import nl.requios.effortlessbuilding.gui.SettingsGui;
import nl.requios.effortlessbuilding.network.BuildSettingsMessage;
import nl.requios.effortlessbuilding.network.QuickReplaceMessage;
import org.lwjgl.input.Keyboard;
@Mod.EventBusSubscriber(Side.CLIENT)
@@ -58,7 +60,12 @@ public class ClientProxy implements IProxy {
@Override
public EntityPlayer getPlayerEntityFromContext(MessageContext ctx) {
return (ctx.side.isClient() ? Minecraft.getMinecraft().player : EffortlessBuilding.proxy.getPlayerEntityFromContext(ctx));
return Minecraft.getMinecraft().player;//(ctx.side.isClient() ? Minecraft.getMinecraft().player : EffortlessBuilding.proxy.getPlayerEntityFromContext(ctx));
}
@Override
public IThreadListener getThreadListenerFromContext(MessageContext ctx) {
return Minecraft.getMinecraft();//(ctx.side.isClient() ? Minecraft.getMinecraft() : EffortlessBuilding.proxy.getThreadListenerFromContext(ctx));
}
@Override

View File

@@ -1,6 +1,7 @@
package nl.requios.effortlessbuilding.proxy;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.IThreadListener;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
@@ -33,8 +34,10 @@ public interface IProxy
/**
* Returns a side-appropriate EntityPlayer for use during message handling.
*
* @param parContext the context
* @param ctx the context
* @return the player entity from context
*/
EntityPlayer getPlayerEntityFromContext(MessageContext parContext);
EntityPlayer getPlayerEntityFromContext(MessageContext ctx);
IThreadListener getThreadListenerFromContext(MessageContext ctx);
}

View File

@@ -1,11 +1,18 @@
package nl.requios.effortlessbuilding.proxy;
import net.minecraft.client.entity.AbstractClientPlayer;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.util.IThreadListener;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.event.FMLServerStartingEvent;
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
import net.minecraftforge.fml.relauncher.Side;
import nl.requios.effortlessbuilding.EffortlessBuilding;
import nl.requios.effortlessbuilding.network.BuildSettingsMessage;
import nl.requios.effortlessbuilding.network.QuickReplaceMessage;
public class ServerProxy implements IProxy
{
@@ -35,4 +42,9 @@ public class ServerProxy implements IProxy
{
return ctx.getServerHandler().player;
}
@Override
public IThreadListener getThreadListenerFromContext(MessageContext ctx) {
return ((EntityPlayerMP) getPlayerEntityFromContext(ctx)).getServerWorld();
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 358 B

After

Width:  |  Height:  |  Size: 376 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 358 B