Made Firework Box a lot more customizable

This commit is contained in:
Ellpeck 2016-12-29 21:29:00 +01:00
parent a7a802d3c8
commit 66309b0488
10 changed files with 343 additions and 62 deletions

View file

@ -11,7 +11,9 @@
package de.ellpeck.actuallyadditions.mod.blocks;
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
import de.ellpeck.actuallyadditions.mod.blocks.base.BlockContainerBase;
import de.ellpeck.actuallyadditions.mod.inventory.GuiHandler;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityFireworkBox;
import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material;
@ -35,17 +37,25 @@ public class BlockFireworkBox extends BlockContainerBase{
this.setSoundType(SoundType.STONE);
}
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing par6, float par7, float par8, float par9){
if(this.tryToggleRedstone(world, pos, player)){
return true;
}
else if(!world.isRemote){
TileEntityFireworkBox grinder = (TileEntityFireworkBox)world.getTileEntity(pos);
if(grinder != null){
player.openGui(ActuallyAdditions.instance, GuiHandler.GuiTypes.FIREWORK_BOX.ordinal(), world, pos.getX(), pos.getY(), pos.getZ());
}
}
return true;
}
@Override
public TileEntity createNewTileEntity(World world, int par2){
return new TileEntityFireworkBox();
}
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing par6, float par7, float par8, float par9){
return this.tryToggleRedstone(world, pos, player);
}
@Override
public EnumRarity getRarity(ItemStack stack){
return EnumRarity.RARE;

View file

@ -0,0 +1,28 @@
/*
* This file ("ContainerFireworkBox.java") is part of the Actually Additions mod for Minecraft.
* It is created and owned by Ellpeck and distributed
* under the Actually Additions License to be found at
* http://ellpeck.de/actaddlicense
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
*
* © 2015-2016 Ellpeck
*/
package de.ellpeck.actuallyadditions.mod.inventory;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.item.ItemStack;
public class ContainerFireworkBox extends Container{
@Override
public ItemStack transferStackInSlot(EntityPlayer playerIn, int index){
return null;
}
@Override
public boolean canInteractWith(EntityPlayer playerIn){
return true;
}
}

View file

@ -0,0 +1,112 @@
/*
* This file ("GuiFireworkBox.java") is part of the Actually Additions mod for Minecraft.
* It is created and owned by Ellpeck and distributed
* under the Actually Additions License to be found at
* http://ellpeck.de/actaddlicense
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
*
* © 2015-2016 Ellpeck
*/
package de.ellpeck.actuallyadditions.mod.inventory;
import de.ellpeck.actuallyadditions.mod.network.PacketHandlerHelper;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityFireworkBox;
import de.ellpeck.actuallyadditions.mod.util.AssetUtil;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiPageButtonList.GuiResponder;
import net.minecraft.client.gui.GuiSlider;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class GuiFireworkBox extends GuiContainer implements GuiResponder{
private final TileEntityFireworkBox tile;
public GuiFireworkBox(TileEntity tile){
super(new ContainerFireworkBox());
this.tile = (TileEntityFireworkBox)tile;
this.xSize = 300;
this.ySize = 120;
}
@Override
public void initGui(){
super.initGui();
this.buttonList.add(new CustomSlider(this, 0, this.guiLeft, this.guiTop, "Value Play", 0F, 5F, this.tile.intValuePlay, IntFormatter.INSTANCE));
this.buttonList.add(new CustomSlider(this, 1, this.guiLeft, this.guiTop+20, "Average Charge Amount", 1F, 4F, this.tile.chargeAmount, IntFormatter.INSTANCE));
this.buttonList.add(new CustomSlider(this, 2, this.guiLeft, this.guiTop+40, "Average Flight Time", 1F, 3F, this.tile.flightTime, IntFormatter.INSTANCE));
this.buttonList.add(new CustomSlider(this, 3, this.guiLeft, this.guiTop+60, "Effect Chance", 0F, 1F, this.tile.trailOrFlickerChance, null));
this.buttonList.add(new CustomSlider(this, 4, this.guiLeft, this.guiTop+80, "Flicker/Trail Ratio", 0F, 1F, this.tile.flickerChance, null));
this.buttonList.add(new CustomSlider(this, 5, this.guiLeft, this.guiTop+100, "Color Amount", 1, 6, this.tile.colorAmount, IntFormatter.INSTANCE));
this.buttonList.add(new CustomSlider(this, 6, this.guiLeft+150, this.guiTop, "Small Ball", 0F, 1F, this.tile.typeChance0, null));
this.buttonList.add(new CustomSlider(this, 7, this.guiLeft+150, this.guiTop+20, "Large Ball", 0F, 1F, this.tile.typeChance1, null));
this.buttonList.add(new CustomSlider(this, 8, this.guiLeft+150, this.guiTop+40, "Star Shape", 0F, 1F, this.tile.typeChance2, null));
this.buttonList.add(new CustomSlider(this, 9, this.guiLeft+150, this.guiTop+60, "Creeper Shape", 0F, 1F, this.tile.typeChance3, null));
this.buttonList.add(new CustomSlider(this, 10, this.guiLeft+150, this.guiTop+80, "Burst", 0F, 1F, this.tile.typeChance4, null));
this.buttonList.add(new CustomSlider(this, 11, this.guiLeft+150, this.guiTop+100, "Area of Effect", 0, 4, this.tile.areaOfEffect, IntFormatter.INSTANCE));
}
@Override
public void setEntryValue(int id, float value){
GuiButton button = this.buttonList.get(id);
if(button instanceof GuiSlider){
if(!((GuiSlider)button).isMouseDown){
System.out.println("SETTING VALUE FOR "+id+"!!");
PacketHandlerHelper.sendNumberPacket(this.tile, value, id);
}
}
}
@Override
protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY){
}
@Override
public void drawGuiContainerForegroundLayer(int x, int y){
AssetUtil.displayNameString(this.fontRendererObj, this.xSize, -10, this.tile);
}
@Override
public void setEntryValue(int id, boolean value){
}
@Override
public void setEntryValue(int id, String value){
}
private static class CustomSlider extends GuiSlider{
private final GuiResponder responder;
public CustomSlider(GuiResponder guiResponder, int idIn, int x, int y, String name, float min, float max, float defaultValue, FormatHelper formatter){
super(guiResponder, idIn, x, y, name, min, max, defaultValue, formatter);
this.responder = guiResponder;
}
@Override
public void mouseReleased(int mouseX, int mouseY){
super.mouseReleased(mouseX, mouseY);
this.responder.setEntryValue(this.id, this.getSliderValue());
}
}
private static class IntFormatter implements GuiSlider.FormatHelper{
public static final IntFormatter INSTANCE = new IntFormatter();
@Override
public String getText(int id, String name, float value){
return name+": "+(int)value;
}
}
}

View file

@ -107,6 +107,8 @@ public class GuiHandler implements IGuiHandler{
return new ContainerBioReactor(player.inventory, tile);
case FARMER:
return new ContainerFarmer(player.inventory, tile);
case FIREWORK_BOX:
return new ContainerFireworkBox();
default:
return null;
}
@ -136,9 +138,9 @@ public class GuiHandler implements IGuiHandler{
case FURNACE_DOUBLE:
return new GuiFurnaceDouble(player.inventory, tile);
case INPUTTER:
return new GuiInputter(player.inventory, tile, x, y, z, world, false);
return new GuiInputter(player.inventory, tile, false);
case INPUTTER_ADVANCED:
return new GuiInputter(player.inventory, tile, x, y, z, world, true);
return new GuiInputter(player.inventory, tile, true);
case REPAIRER:
return new GuiRepairer(player.inventory, tile);
case BREAKER:
@ -202,6 +204,8 @@ public class GuiHandler implements IGuiHandler{
return new GuiBioReactor(player.inventory, tile);
case FARMER:
return new GuiFarmer(player.inventory, tile);
case FIREWORK_BOX:
return new GuiFireworkBox(tile);
default:
return null;
}
@ -242,7 +246,8 @@ public class GuiHandler implements IGuiHandler{
BAG(false),
VOID_BAG(false),
BIO_REACTOR,
FARMER;
FARMER,
FIREWORK_BOX;
public final boolean checkTileEntity;

View file

@ -11,8 +11,6 @@
package de.ellpeck.actuallyadditions.mod.inventory.gui;
import de.ellpeck.actuallyadditions.mod.inventory.ContainerInputter;
import de.ellpeck.actuallyadditions.mod.network.PacketClientToServer;
import de.ellpeck.actuallyadditions.mod.network.PacketHandler;
import de.ellpeck.actuallyadditions.mod.network.PacketHandlerHelper;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityBase;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityInputter;
@ -25,9 +23,7 @@ import net.minecraft.client.gui.GuiTextField;
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.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import org.lwjgl.input.Keyboard;
@ -49,10 +45,6 @@ public class GuiInputter extends GuiContainer{
private static final ResourceLocation RES_LOC = AssetUtil.getGuiLocation("gui_inputter");
private static final ResourceLocation RES_LOC_ADVANCED = AssetUtil.getGuiLocation("gui_inputter_advanced");
public final TileEntityInputter tileInputter;
private final int x;
private final int y;
private final int z;
private final World world;
private final boolean isAdvanced;
private GuiTextField fieldPutStart;
private GuiTextField fieldPutEnd;
@ -62,13 +54,9 @@ public class GuiInputter extends GuiContainer{
private FilterSettingsGui leftFilter;
private FilterSettingsGui rightFilter;
public GuiInputter(InventoryPlayer inventory, TileEntityBase tile, int x, int y, int z, World world, boolean isAdvanced){
public GuiInputter(InventoryPlayer inventory, TileEntityBase tile, boolean isAdvanced){
super(new ContainerInputter(inventory, tile, isAdvanced));
this.tileInputter = (TileEntityInputter)tile;
this.x = x;
this.y = y;
this.z = z;
this.world = world;
this.xSize = 176;
this.ySize = 97+86+(isAdvanced ? OFFSET_ADVANCED : 0);
this.isAdvanced = isAdvanced;
@ -228,15 +216,7 @@ public class GuiInputter extends GuiContainer{
}
private void sendPacket(int text, int textID){
NBTTagCompound compound = new NBTTagCompound();
compound.setInteger("X", this.x);
compound.setInteger("Y", this.y);
compound.setInteger("Z", this.z);
compound.setInteger("WorldID", this.world.provider.getDimension());
compound.setInteger("PlayerID", Minecraft.getMinecraft().player.getEntityId());
compound.setInteger("NumberID", textID);
compound.setInteger("Number", text);
PacketHandler.theNetwork.sendToServer(new PacketClientToServer(compound, PacketHandler.GUI_NUMBER_TO_TILE_HANDLER));
PacketHandlerHelper.sendNumberPacket(this.tileInputter, text, textID);
}
private int parse(String theInt){

View file

@ -121,7 +121,7 @@ public final class PacketHandler{
if(tile instanceof INumberReactor){
INumberReactor reactor = (INumberReactor)tile;
reactor.onNumberReceived(compound.getInteger("Number"), compound.getInteger("NumberID"), (EntityPlayer)world.getEntityByID(compound.getInteger("PlayerID")));
reactor.onNumberReceived(compound.getDouble("Number"), compound.getInteger("NumberID"), (EntityPlayer)world.getEntityByID(compound.getInteger("PlayerID")));
}
}
};

View file

@ -51,4 +51,16 @@ public final class PacketHandlerHelper{
PacketHandler.theNetwork.sendToServer(new PacketClientToServer(compound, PacketHandler.CHANGE_PLAYER_DATA_HANDLER));
}
}
public static void sendNumberPacket(TileEntity tile, double number, int id){
NBTTagCompound compound = new NBTTagCompound();
compound.setInteger("X", tile.getPos().getX());
compound.setInteger("Y", tile.getPos().getY());
compound.setInteger("Z", tile.getPos().getZ());
compound.setInteger("WorldID", tile.getWorld().provider.getDimension());
compound.setInteger("PlayerID", Minecraft.getMinecraft().player.getEntityId());
compound.setInteger("NumberID", id);
compound.setDouble("Number", number);
PacketHandler.theNetwork.sendToServer(new PacketClientToServer(compound, PacketHandler.GUI_NUMBER_TO_TILE_HANDLER));
}
}

View file

@ -17,9 +17,9 @@ public interface INumberReactor{
/**
* Called when a Number gets received after typing it in in the GUI
*
* @param text The number that was sent (I don't remember why I called it text. Had a reason though.)
* @param textID The ID (meaning the place in the GUI) of the number typed in
* @param number The number that was sent
* @param id The ID (meaning the place in the GUI) of the number typed in
* @param player The Player doing it
*/
void onNumberReceived(int text, int textID, EntityPlayer player);
void onNumberReceived(double number, int id, EntityPlayer player);
}

View file

@ -10,55 +10,167 @@
package de.ellpeck.actuallyadditions.mod.tile;
import de.ellpeck.actuallyadditions.mod.network.gui.INumberReactor;
import net.minecraft.entity.item.EntityFireworkRocket;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Items;
import net.minecraft.item.ItemDye;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.WeightedRandom;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.world.World;
import net.minecraftforge.energy.IEnergyStorage;
public class TileEntityFireworkBox extends TileEntityBase implements IEnergyDisplay{
import java.util.ArrayList;
import java.util.List;
public static final int USE_PER_SHOT = 300;
public class TileEntityFireworkBox extends TileEntityBase implements IEnergyDisplay, INumberReactor{
public static final int USE_PER_SHOT = 500;
public final CustomEnergyStorage storage = new CustomEnergyStorage(20000, 200, 0);
private int timeUntilNextFirework;
private int oldEnergy;
public int intValuePlay = 2;
public int chargeAmount = 2;
public int flightTime = 2;
public float trailOrFlickerChance = 0.65F;
public float flickerChance = 0.25F;
public int colorAmount = 3;
public float typeChance0 = 1F;
public float typeChance1 = 0F;
public float typeChance2 = 0F;
public float typeChance3 = 0F;
public float typeChance4 = 0F;
public int areaOfEffect = 2;
public TileEntityFireworkBox(){
super("fireworkBox");
}
@Override
public void writeSyncableNBT(NBTTagCompound compound, NBTType type){
super.writeSyncableNBT(compound, type);
this.storage.writeToNBT(compound);
if(type != NBTType.SAVE_BLOCK){
compound.setInteger("Play", this.intValuePlay);
compound.setInteger("ChargeAmount", this.chargeAmount);
compound.setInteger("FlightTime", this.flightTime);
compound.setFloat("TrailFlickerChance", this.trailOrFlickerChance);
compound.setFloat("FlickerChance", this.flickerChance);
compound.setInteger("ColorAmount", this.colorAmount);
compound.setFloat("TypeChance0", this.typeChance0);
compound.setFloat("TypeChance1", this.typeChance1);
compound.setFloat("TypeChance2", this.typeChance2);
compound.setFloat("TypeChance3", this.typeChance3);
compound.setFloat("TypeChance4", this.typeChance4);
compound.setInteger("Area", this.areaOfEffect);
}
}
@Override
public void readSyncableNBT(NBTTagCompound compound, NBTType type){
super.readSyncableNBT(compound, type);
this.storage.readFromNBT(compound);
if(type != NBTType.SAVE_BLOCK){
this.intValuePlay = compound.getInteger("Play");
this.chargeAmount = compound.getInteger("ChargeAmount");
this.flightTime = compound.getInteger("FlightTime");
this.trailOrFlickerChance = compound.getFloat("TrailFlickerChance");
this.flickerChance = compound.getFloat("FlickerChance");
this.colorAmount = compound.getInteger("ColorAmount");
this.typeChance0 = compound.getFloat("TypeChance0");
this.typeChance1 = compound.getFloat("TypeChance1");
this.typeChance2 = compound.getFloat("TypeChance2");
this.typeChance3 = compound.getFloat("TypeChance3");
this.typeChance4 = compound.getFloat("TypeChance4");
this.areaOfEffect = compound.getInteger("Area");
}
}
@Override
public void onNumberReceived(double number, int id, EntityPlayer player){
switch(id){
case 0:
this.intValuePlay = (int)number;
break;
case 1:
this.chargeAmount = (int)number;
break;
case 2:
this.flightTime = (int)number;
break;
case 3:
this.trailOrFlickerChance = (float)number;
break;
case 4:
this.flickerChance = (float)number;
break;
case 5:
this.colorAmount = (int)number;
break;
case 6:
this.typeChance0 = (float)number;
break;
case 7:
this.typeChance1 = (float)number;
break;
case 8:
this.typeChance2 = (float)number;
break;
case 9:
this.typeChance3 = (float)number;
break;
case 10:
this.typeChance4 = (float)number;
break;
case 11:
this.areaOfEffect = (int)number;
break;
}
this.sendUpdate();
}
public void spawnFireworks(World world, double x, double y, double z){
int range = 4;
int amount = world.rand.nextInt(5)+1;
for(int i = 0; i < amount; i++){
ItemStack firework = this.makeFirework();
ItemStack firework = this.makeFirework();
double newX = x+MathHelper.nextDouble(this.world.rand, 0, range*2)-range;
double newZ = z+MathHelper.nextDouble(this.world.rand, 0, range*2)-range;
double newX = x+this.getRandomAoe();
double newZ = z+this.getRandomAoe();
if(world.isBlockLoaded(new BlockPos(newX, y, newZ))){
EntityFireworkRocket rocket = new EntityFireworkRocket(world, newX, y+0.5, newZ, firework);
world.spawnEntity(rocket);
}
if(world.isBlockLoaded(new BlockPos(newX, y, newZ))){
EntityFireworkRocket rocket = new EntityFireworkRocket(world, newX, y+1, newZ, firework);
world.spawnEntity(rocket);
}
}
private double getRandomAoe(){
if(this.areaOfEffect <= 0){
return 0.5;
}
else{
return MathHelper.nextDouble(this.world.rand, 0, this.areaOfEffect*2)-this.areaOfEffect;
}
}
private ItemStack makeFirework(){
NBTTagList list = new NBTTagList();
int chargesAmount = this.world.rand.nextInt(2)+1;
for(int i = 0; i < chargesAmount; i++){
for(int i = 0; i < this.getRandomWithPlay(this.chargeAmount); i++){
list.appendTag(this.makeFireworkCharge());
}
NBTTagCompound compound1 = new NBTTagCompound();
compound1.setTag("Explosions", list);
compound1.setByte("Flight", (byte)(this.world.rand.nextInt(3)+1));
compound1.setByte("Flight", (byte)this.getRandomWithPlay(this.flightTime));
NBTTagCompound compound = new NBTTagCompound();
compound.setTag("Fireworks", compound1);
@ -72,8 +184,8 @@ public class TileEntityFireworkBox extends TileEntityBase implements IEnergyDisp
private NBTTagCompound makeFireworkCharge(){
NBTTagCompound compound = new NBTTagCompound();
if(this.world.rand.nextFloat() >= 0.65F){
if(this.world.rand.nextFloat() >= 0.5F){
if(this.world.rand.nextFloat() >= this.trailOrFlickerChance){
if(this.world.rand.nextFloat() >= this.flickerChance){
compound.setBoolean("Flicker", true);
}
else{
@ -81,27 +193,37 @@ public class TileEntityFireworkBox extends TileEntityBase implements IEnergyDisp
}
}
int[] colors = new int[MathHelper.getInt(this.world.rand, 1, 6)];
int[] colors = new int[this.getRandomWithPlay(this.colorAmount)];
for(int i = 0; i < colors.length; i++){
colors[i] = ItemDye.DYE_COLORS[this.world.rand.nextInt(ItemDye.DYE_COLORS.length)];
}
compound.setIntArray("Colors", colors);
compound.setByte("Type", (byte)this.world.rand.nextInt(5));
compound.setByte("Type", (byte)this.getRandomType());
return compound;
}
@Override
public void writeSyncableNBT(NBTTagCompound compound, NBTType type){
super.writeSyncableNBT(compound, type);
this.storage.writeToNBT(compound);
private int getRandomWithPlay(int value){
return MathHelper.clamp(MathHelper.getInt(this.world.rand, value-this.intValuePlay, value+this.intValuePlay), 1, 6);
}
@Override
public void readSyncableNBT(NBTTagCompound compound, NBTType type){
super.readSyncableNBT(compound, type);
this.storage.readFromNBT(compound);
private int getRandomType(){
List<WeightedFireworkType> possible = new ArrayList<WeightedFireworkType>();
possible.add(new WeightedFireworkType(0, this.typeChance0));
possible.add(new WeightedFireworkType(1, this.typeChance1));
possible.add(new WeightedFireworkType(2, this.typeChance2));
possible.add(new WeightedFireworkType(3, this.typeChance3));
possible.add(new WeightedFireworkType(4, this.typeChance4));
int weight = WeightedRandom.getTotalWeight(possible);
if(weight <= 0){
return 0;
}
else{
return WeightedRandom.getRandomItem(this.world.rand, possible, weight).type;
}
}
@Override
@ -159,4 +281,14 @@ public class TileEntityFireworkBox extends TileEntityBase implements IEnergyDisp
public IEnergyStorage getEnergyStorage(EnumFacing facing){
return this.storage;
}
private static class WeightedFireworkType extends WeightedRandom.Item{
public final int type;
public WeightedFireworkType(int type, float chance){
super((int)(chance*100F));
this.type = type;
}
}
}

View file

@ -54,7 +54,9 @@ public class TileEntityInputter extends TileEntityInventoryBase implements IButt
}
@Override
public void onNumberReceived(int text, int textID, EntityPlayer player){
public void onNumberReceived(double number, int textID, EntityPlayer player){
int text = (int)number;
if(text != -1){
if(textID == 0){
this.slotToPutStart = Math.max(text, 0);