mirror of
https://github.com/HbmMods/Hbm-s-Nuclear-Tech-GIT.git
synced 2026-01-25 10:32:49 +00:00
Merge pull request #1965 from Toshayo/master
Redstone-over-Radio OpenComputers integration + Mining satellite NEI handler
This commit is contained in:
commit
5a9b65095d
189
src/main/java/com/hbm/handler/nei/SatelliteHandler.java
Normal file
189
src/main/java/com/hbm/handler/nei/SatelliteHandler.java
Normal file
@ -0,0 +1,189 @@
|
||||
package com.hbm.handler.nei;
|
||||
|
||||
import codechicken.nei.NEIServerUtils;
|
||||
import codechicken.nei.PositionedStack;
|
||||
import codechicken.nei.recipe.TemplateRecipeHandler;
|
||||
import com.hbm.blocks.ModBlocks;
|
||||
import com.hbm.handler.imc.ICompatNHNEI;
|
||||
import com.hbm.itempool.ItemPool;
|
||||
import com.hbm.itempool.ItemPoolsSatellite;
|
||||
import com.hbm.items.ModItems;
|
||||
import com.hbm.lib.RefStrings;
|
||||
import com.hbm.saveddata.satellites.SatelliteMiner;
|
||||
import com.hbm.util.ItemStackUtil;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.EnumChatFormatting;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import net.minecraft.util.WeightedRandomChestContent;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import static codechicken.lib.gui.GuiDraw.drawTexturedModalRect;
|
||||
|
||||
public class SatelliteHandler extends TemplateRecipeHandler implements ICompatNHNEI {
|
||||
@Override
|
||||
public ItemStack[] getMachinesForRecipe() {
|
||||
return new ItemStack[] {
|
||||
new ItemStack(ModBlocks.sat_dock)
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRecipeID() {
|
||||
return "ntmSatellite";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRecipeName() {
|
||||
return "Satellite";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getGuiTexture() {
|
||||
return RefStrings.MODID + ":textures/gui/nei/gui_nei_anvil.png";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadCraftingRecipes(String outputId, Object... results) {
|
||||
if(outputId.equals("ntmSatellite")) {
|
||||
for(Item satelliteItem : new Item[]{ModItems.sat_miner, ModItems.sat_lunar_miner}) {
|
||||
String poolName = SatelliteMiner.getCargoForItem(satelliteItem);
|
||||
if(poolName == null) {
|
||||
continue;
|
||||
}
|
||||
this.addRecipeToList(satelliteItem, ItemPool.getPool(poolName));
|
||||
}
|
||||
} else {
|
||||
super.loadCraftingRecipes(outputId, results);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadCraftingRecipes(ItemStack result) {
|
||||
for(Item satelliteItem : new Item[]{ModItems.sat_miner, ModItems.sat_lunar_miner}) {
|
||||
String poolName = SatelliteMiner.getCargoForItem(satelliteItem);
|
||||
if(poolName == null) {
|
||||
continue;
|
||||
}
|
||||
WeightedRandomChestContent[] pool = ItemPool.getPool(poolName);
|
||||
for(WeightedRandomChestContent poolEntry : pool) {
|
||||
if(NEIServerUtils.areStacksSameTypeCrafting(poolEntry.theItemId, result)) {
|
||||
this.addRecipeToList(satelliteItem, pool);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadUsageRecipes(String inputId, Object... ingredients) {
|
||||
if(inputId.equals("ntmSatellite")) {
|
||||
loadCraftingRecipes("ntmSatellite");
|
||||
} else {
|
||||
super.loadUsageRecipes(inputId, ingredients);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadUsageRecipes(ItemStack ingredient) {
|
||||
if(ingredient.getItem() == ModItems.sat_miner) {
|
||||
this.addRecipeToList(ModItems.sat_miner, ItemPool.getPool(ItemPoolsSatellite.POOL_SAT_MINER));
|
||||
} else if(ingredient.getItem() == ModItems.sat_lunar_miner) {
|
||||
this.addRecipeToList(ModItems.sat_lunar_miner, ItemPool.getPool(ItemPoolsSatellite.POOL_SAT_LUNAR));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void addRecipeToList(Item poolItem, WeightedRandomChestContent[] poolEntries) {
|
||||
List<ItemStack> outs = new ArrayList<>();
|
||||
int weight = Arrays.stream(poolEntries).mapToInt(poolEntry -> poolEntry.itemWeight).sum();
|
||||
|
||||
for(WeightedRandomChestContent poolEntry : poolEntries) {
|
||||
ItemStack stack = poolEntry.theItemId.copy();
|
||||
|
||||
float chance = 100F * poolEntry.itemWeight / weight;
|
||||
ItemStackUtil.addTooltipToStack(stack, EnumChatFormatting.RED + "" + ((int)(chance * 10F) / 10F) + "%");
|
||||
|
||||
outs.add(stack);
|
||||
}
|
||||
|
||||
this.arecipes.add(new RecipeSet(new ItemStack(poolItem), outs));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawBackground(int recipe) {
|
||||
super.drawBackground(recipe);
|
||||
|
||||
drawTexturedModalRect(11, 23, 113, 105, 18, 18); //in
|
||||
drawTexturedModalRect(47, 5, 5, 87, 108, 54); //out
|
||||
drawTexturedModalRect(29, 14, 131, 96, 18, 36); //operation
|
||||
}
|
||||
|
||||
public class RecipeSet extends TemplateRecipeHandler.CachedRecipe {
|
||||
List<PositionedStack> input = new ArrayList<>();
|
||||
List<PositionedStack> output = new ArrayList<>();
|
||||
PositionedStack satelliteDock;
|
||||
|
||||
public RecipeSet(Object in, List<ItemStack> out) {
|
||||
//not the prettiest of solutions but certainly the most pleasant to work with
|
||||
int inLine = 1;
|
||||
int outLine = 1;
|
||||
int inOX = 0;
|
||||
int inOY = 0;
|
||||
int outOX = 0;
|
||||
int outOY = 0;
|
||||
int anvX = 0;
|
||||
int anvY = 31;
|
||||
|
||||
outLine = 6;
|
||||
inOX = 12;
|
||||
inOY = 24;
|
||||
outOX = 48;
|
||||
outOY = 6;
|
||||
anvX = 30;
|
||||
|
||||
this.input.add(new PositionedStack(in, inOX, inOY));
|
||||
|
||||
int overflowCount = out.size() / 18;
|
||||
for(int i = 0; i < Math.min(out.size(), 18); i++) {
|
||||
ItemStack[] stacks = new ItemStack[overflowCount + 1];
|
||||
for(int j = 0; j < overflowCount + 1 && j * 18 + i < out.size(); j++) {
|
||||
stacks[j] = out.get(j * 18 + i);
|
||||
}
|
||||
this.output.add(new PositionedStack(stacks, outOX + 18 * (i % outLine), outOY + 18 * (i / outLine)));
|
||||
}
|
||||
|
||||
this.satelliteDock = new PositionedStack(new ItemStack(ModBlocks.sat_dock), anvX, anvY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PositionedStack> getIngredients() {
|
||||
return getCycledIngredients(cycleticks / 20, input);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PositionedStack getResult() {
|
||||
return output.get(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PositionedStack> getOtherStacks() {
|
||||
ArrayList<PositionedStack> stacks = new ArrayList<>(output);
|
||||
stacks.add(satelliteDock);
|
||||
return getCycledIngredients(cycleticks / 20, stacks);
|
||||
}
|
||||
}
|
||||
|
||||
private static HashMap<ItemStack, ItemStack> getRecipeMap() {
|
||||
HashMap<ItemStack, ItemStack> recipeMap = new HashMap<>();
|
||||
ItemStack minerStack = new ItemStack(ModItems.sat_miner);
|
||||
ItemStack lunarMinerStack = new ItemStack(ModItems.sat_lunar_miner);
|
||||
Arrays.stream(ItemPool.getPool(ItemPoolsSatellite.POOL_SAT_MINER)).forEach(poolEntry -> recipeMap.put(minerStack, poolEntry.theItemId));
|
||||
Arrays.stream(ItemPool.getPool(ItemPoolsSatellite.POOL_SAT_LUNAR)).forEach(poolEntry -> recipeMap.put(lunarMinerStack, poolEntry.theItemId));
|
||||
return recipeMap;
|
||||
}
|
||||
}
|
||||
@ -43,6 +43,7 @@ public class NEIRegistry {
|
||||
handlers.add(new CrucibleCastingHandler());
|
||||
handlers.add(new ToolingHandler());
|
||||
handlers.add(new ConstructionHandler());
|
||||
handlers.add(new SatelliteHandler());
|
||||
|
||||
//universal boyes
|
||||
handlers.add(new ZirnoxRecipeHandler());
|
||||
|
||||
@ -2,6 +2,7 @@ package com.hbm.saveddata.satellites;
|
||||
|
||||
import com.hbm.itempool.ItemPoolsSatellite;
|
||||
import com.hbm.util.WeightedRandomObject;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
import java.util.HashMap;
|
||||
@ -42,6 +43,16 @@ public class SatelliteMiner extends Satellite {
|
||||
return CARGO.get(getClass());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the cargo key for the satellite item. If the item is not a miner satellite null is returned.
|
||||
* @param satelliteItem - Satellite item
|
||||
* @return - Returns {@link com.hbm.itempool.ItemPool} key or null if the item is not a mining satellite.
|
||||
*/
|
||||
public static String getCargoForItem(Item satelliteItem) {
|
||||
Class<? extends Satellite> satelliteClass = itemToClass.getOrDefault(satelliteItem, null);
|
||||
return satelliteClass != null ? CARGO.getOrDefault(satelliteClass, null) : null;
|
||||
}
|
||||
|
||||
static {
|
||||
registerCargo(SatelliteMiner.class, ItemPoolsSatellite.POOL_SAT_MINER);
|
||||
}
|
||||
|
||||
@ -1,17 +1,24 @@
|
||||
package com.hbm.tileentity.network;
|
||||
|
||||
import com.hbm.handler.CompatHandler;
|
||||
import com.hbm.interfaces.IControlReceiver;
|
||||
|
||||
import com.hbm.tileentity.TileEntityLoadedBase;
|
||||
import com.hbm.util.BufferUtil;
|
||||
import cpw.mods.fml.common.Optional;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import li.cil.oc.api.machine.Arguments;
|
||||
import li.cil.oc.api.machine.Callback;
|
||||
import li.cil.oc.api.machine.Context;
|
||||
import li.cil.oc.api.network.SimpleComponent;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.network.NetworkManager;
|
||||
import net.minecraft.network.Packet;
|
||||
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
|
||||
|
||||
public class TileEntityRadioTorchBase extends TileEntityLoadedBase implements IControlReceiver {
|
||||
@Optional.InterfaceList({@Optional.Interface(iface = "li.cil.oc.api.network.SimpleComponent", modid = "OpenComputers")})
|
||||
public class TileEntityRadioTorchBase extends TileEntityLoadedBase implements IControlReceiver, SimpleComponent, CompatHandler.OCComponent {
|
||||
|
||||
/** channel we're broadcasting on/listening to */
|
||||
public String channel = "";
|
||||
@ -103,4 +110,31 @@ public class TileEntityRadioTorchBase extends TileEntityLoadedBase implements IC
|
||||
|
||||
this.markDirty();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Optional.Method(modid = "OpenComputers")
|
||||
public String getComponentName() {
|
||||
return "radio_torch";
|
||||
}
|
||||
|
||||
@Callback(direct = true, limit = 4, doc = "setChannle(channel: string) -- Set the channel the torch is listening/broadcasting to")
|
||||
@Optional.Method(modid = "OpenComputers")
|
||||
public Object[] setChannel(Context context, Arguments args) {
|
||||
channel = args.checkString(0);
|
||||
return new Object[] {};
|
||||
}
|
||||
|
||||
@Callback(direct = true, limit = 4, doc = "setPolling(value: boolean) -- Switches state change mode to tick-based polling")
|
||||
@Optional.Method(modid = "OpenComputers")
|
||||
public Object[] setPolling(Context context, Arguments args) {
|
||||
polling = args.checkBoolean(0);
|
||||
return new Object[] {};
|
||||
}
|
||||
|
||||
@Callback(direct = true, limit = 4, doc = "setCustomMap(value: boolean) -- Switches redstone passthrough to custom signal mapping")
|
||||
@Optional.Method(modid = "OpenComputers")
|
||||
public Object[] setCustomMap(Context context, Arguments args) {
|
||||
customMap = args.checkBoolean(0);
|
||||
return new Object[] {};
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user