Phantom Placer side rules

This commit is contained in:
Ellpeck 2016-07-06 20:05:56 +02:00
parent 5cefc43aca
commit b1f1102f94
3 changed files with 88 additions and 3 deletions

View file

@ -11,16 +11,29 @@
package de.ellpeck.actuallyadditions.mod.inventory.gui;
import de.ellpeck.actuallyadditions.mod.inventory.ContainerPhantomPlacer;
import de.ellpeck.actuallyadditions.mod.network.PacketClientToServer;
import de.ellpeck.actuallyadditions.mod.network.PacketHandler;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityBase;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityPhantomPlacer;
import de.ellpeck.actuallyadditions.mod.util.AssetUtil;
import de.ellpeck.actuallyadditions.mod.util.ModUtil;
import de.ellpeck.actuallyadditions.mod.util.StringUtil;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.TextFormatting;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
@SideOnly(Side.CLIENT)
public class GuiPhantomPlacer extends GuiContainer{
@ -34,6 +47,57 @@ public class GuiPhantomPlacer extends GuiContainer{
this.ySize = 93+86;
}
@Override
public void initGui(){
super.initGui();
if(!this.placer.isBreaker){
this.buttonList.add(new GuiButton(0, this.guiLeft+63, this.guiTop+75, 50, 20, this.getSide()));
}
}
@Override
public void updateScreen(){
super.updateScreen();
if(!this.placer.isBreaker){
this.buttonList.get(0).displayString = this.getSide();
}
}
@Override
public void drawScreen(int mouseX, int mouseY, float partialTicks){
super.drawScreen(mouseX, mouseY, partialTicks);
if(!this.placer.isBreaker && this.buttonList.get(0).isMouseOver()){
String loc = "info."+ModUtil.MOD_ID+".placer.sides";
List<String> textList = new ArrayList<String>();
textList.add(TextFormatting.GOLD+StringUtil.localize(loc+".1"));
textList.addAll(this.fontRendererObj.listFormattedStringToWidth(StringUtil.localize(loc+".2"), 200));
this.drawHoveringText(textList, mouseX, mouseY);
}
}
@Override
protected void actionPerformed(GuiButton button) throws IOException{
if(!this.placer.isBreaker){
NBTTagCompound compound = new NBTTagCompound();
BlockPos pos = this.placer.getPos();
compound.setInteger("X", pos.getX());
compound.setInteger("Y", pos.getY());
compound.setInteger("Z", pos.getZ());
compound.setInteger("WorldID", this.placer.getWorld().provider.getDimension());
compound.setInteger("PlayerID", Minecraft.getMinecraft().thePlayer.getEntityId());
compound.setInteger("ButtonID", button.id);
PacketHandler.theNetwork.sendToServer(new PacketClientToServer(compound, PacketHandler.GUI_BUTTON_TO_TILE_HANDLER));
}
}
private String getSide(){
return GuiInputter.SIDES[this.placer.side+1];
}
@Override
public void drawGuiContainerForegroundLayer(int x, int y){
AssetUtil.displayNameString(this.fontRendererObj, this.xSize, -10, this.placer);

View file

@ -13,22 +13,23 @@ package de.ellpeck.actuallyadditions.mod.tile;
import de.ellpeck.actuallyadditions.api.tile.IPhantomTile;
import de.ellpeck.actuallyadditions.mod.config.values.ConfigBoolValues;
import de.ellpeck.actuallyadditions.mod.inventory.GuiHandler;
import de.ellpeck.actuallyadditions.mod.network.gui.IButtonReactor;
import de.ellpeck.actuallyadditions.mod.util.AssetUtil;
import de.ellpeck.actuallyadditions.mod.util.Util;
import de.ellpeck.actuallyadditions.mod.util.WorldUtil;
import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumParticleTypes;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import java.util.ArrayList;
public class TileEntityPhantomPlacer extends TileEntityInventoryBase implements IPhantomTile{
public class TileEntityPhantomPlacer extends TileEntityInventoryBase implements IPhantomTile, IButtonReactor{
public static final int RANGE = 3;
public BlockPos boundPosition;
@ -36,6 +37,7 @@ public class TileEntityPhantomPlacer extends TileEntityInventoryBase implements
public int range;
public boolean isBreaker;
private int oldRange;
public int side;
public TileEntityPhantomPlacer(int slots, String name){
super(slots, name);
@ -56,6 +58,9 @@ public class TileEntityPhantomPlacer extends TileEntityInventoryBase implements
compound.setInteger("YCoordOfTileStored", this.boundPosition.getY());
compound.setInteger("ZCoordOfTileStored", this.boundPosition.getZ());
}
if(!this.isBreaker){
compound.setInteger("Side", this.side);
}
}
}
@ -71,6 +76,9 @@ public class TileEntityPhantomPlacer extends TileEntityInventoryBase implements
this.boundPosition = new BlockPos(x, y, z);
this.markDirty();
}
if(!this.isBreaker){
this.side = compound.getInteger("Side");
}
}
}
@ -142,7 +150,7 @@ public class TileEntityPhantomPlacer extends TileEntityInventoryBase implements
}
else{
int theSlot = WorldUtil.findFirstFilledSlot(this.slots);
this.setInventorySlotContents(theSlot, WorldUtil.useItemAtSide(EnumFacing.UP, this.worldObj, this.boundPosition, this.slots[theSlot]));
this.setInventorySlotContents(theSlot, WorldUtil.useItemAtSide(WorldUtil.getDirectionBySidesInOrder(this.side), this.worldObj, this.boundPosition, this.slots[theSlot]));
if(this.slots[theSlot] != null && this.slots[theSlot].stackSize <= 0){
this.slots[theSlot] = null;
}
@ -218,4 +226,15 @@ public class TileEntityPhantomPlacer extends TileEntityInventoryBase implements
this.doWork();
}
@Override
public void onButtonPressed(int buttonID, EntityPlayer player){
if(this.side+1 >= EnumFacing.values().length){
this.side = 0;
}
else{
this.side++;
}
this.sendUpdate();
}
}

View file

@ -561,6 +561,8 @@ info.actuallyadditions.booklet.manualName.1.5=Actual Addition
info.actuallyadditions.booklet.manualName.2=Manual
info.actuallyadditions.booklet.edition=Edition
info.actuallyadditions.deathRecorded=Your death has been recorded. Use a Death Tracker to find the death location!
info.actuallyadditions.placer.sides.1=Placement Sides
info.actuallyadditions.placer.sides.2=Usually when placing down blocks, they are placed towards the side of another block that you are looking at. Because the Phantom Placer can place blocks in mid-air, it doesn't know that. Usually you should just set it to a solid side.
#Container Names
container.actuallyadditions.inputter.name=ESD