Skip to content

Commit

Permalink
No enchanting fuels == no fuel required
Browse files Browse the repository at this point in the history
Removes the fuel slot when all fuels are removed with CraftTweaker
  • Loading branch information
Roadhog360 committed Jun 15, 2024
1 parent 86de34f commit 8c52c3a
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
@SideOnly(Side.CLIENT)
public class GuiEnchantment extends GuiContainer {

private static final ResourceLocation field_147078_C = Utils.getResource(Reference.MOD_ID + ":textures/gui/container/enchanting_table.png");
private final ResourceLocation TEXTURE;
private static final ResourceLocation field_147070_D = Utils.getResource("textures/entity/enchanting_table_book.png");
private static final ModelBook field_147072_E = new ModelBook();
private final InventoryPlayer field_175379_F;
Expand Down Expand Up @@ -59,8 +59,12 @@ public GuiEnchantment(InventoryPlayer p_i45502_1_, World worldIn, String p_i4550
field_147075_G = (ContainerEnchantment) inventorySlots;
field_175380_I = p_i45502_3_;

TEXTURE = Utils.getResource(
field_147075_G.noFuel ? "textures/gui/container/enchanting_table.png" :
Reference.MOD_ID + ":textures/gui/container/enchanting_table.png");

displayStacks = new ArrayList<>(EnchantingFuelRegistry.getFuels().keySet());
if (!displayStacks.isEmpty()) {
if (displayStacks.size() > 1) {
for (int i = 1; i < displayStacks.size(); i++) {
ItemStack stack = displayStacks.get(i);
if (LAPIS.isItemEqual(stack)) {
Expand All @@ -69,8 +73,8 @@ public GuiEnchantment(InventoryPlayer p_i45502_1_, World worldIn, String p_i4550
break;
}
}
displayItem = displayStacks.get(0);
}
displayItem = field_147075_G.noFuel ? LAPIS : displayStacks.get(0);
}

/**
Expand Down Expand Up @@ -118,7 +122,7 @@ protected void mouseClicked(int mouseX, int mouseY, int mouseButton) {
@Override
protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) {
OpenGLHelper.colour(1, 1, 1);
mc.getTextureManager().bindTexture(field_147078_C);
mc.getTextureManager().bindTexture(TEXTURE);
int k = (width - xSize) / 2;
int l = (height - ySize) / 2;
drawTexturedModalRect(k, l, 0, 0, xSize, ySize);
Expand Down Expand Up @@ -182,7 +186,7 @@ protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, i
byte var16 = 86;
String s = EnchantmentNameParts.instance.generateNewRandomName();
zLevel = 0.0F;
mc.getTextureManager().bindTexture(field_147078_C);
mc.getTextureManager().bindTexture(TEXTURE);
int j1 = field_147075_G.enchantLevels[i1];
OpenGLHelper.colour(1.0F, 1.0F, 1.0F);

Expand Down Expand Up @@ -237,7 +241,7 @@ public void drawScreen(int mouseX, int mouseY, float partialTicks) {
if (func_146978_c(60, 14 + 19 * var6, 108, 17, mouseX, mouseY) && var7 > 0 && var8 >= 0) {
ArrayList<Object> var10 = Lists.newArrayList();
String var11;
if (Enchantment.enchantmentsList[var8 & 255] != null) {
if (Enchantment.enchantmentsList[var8 % Enchantment.enchantmentsList.length] != null) {
var11 = Enchantment.enchantmentsList[var8 & 255].getTranslatedName((var8 & 65280) >> 8);
var10.add(EnumChatFormatting.WHITE.toString() + EnumChatFormatting.ITALIC + I18n.format("container.enchant.clue", var11));
}
Expand All @@ -248,42 +252,31 @@ public void drawScreen(int mouseX, int mouseY, float partialTicks) {
if (mc.thePlayer.experienceLevel < var7)
var10.add(EnumChatFormatting.RED + I18n.format("container.enchant.level.required") + ": " + field_147075_G.enchantLevels[var6]);
else {
var11 = "";

if (EnchantingFuelRegistry.getFuels().isEmpty()) {
var11 = StatCollector.translateToLocal("container.enchant.rusrs");
} else {
if (displayStacks.size() > 1) {
if (viewingTicks > 40) {
viewingTicks = 0;
ArrayList<ItemStack> tempList = new ArrayList<>(displayStacks);
tempList.remove(displayItem);
displayItem = tempList.get(displayRand.nextInt(tempList.size()));
//We don't want to display the same item name twice in a row (because then it looks like it's being displayed for a longer time)
}
}
if (!field_147075_G.noFuel) {
String name;

String name = displayItem.getUnlocalizedName() + ".name";
String prefix = name.equals("container.enchant.lapis.one") ? "" : "%s ";
String text1 = prefix + StatCollector.translateToLocal(name);
String text2 = prefix + StatCollector.translateToLocal(name.equals("item.dyePowder.blue.name") ? "container.enchant.lapis.one" : name);

if (var9 == 1) {
var11 = String.format(text1, 1);
if (displayItem.isItemEqual(LAPIS)) {
name = StatCollector.translateToLocal("container.enchant.lapis." + (var9 > 1 ? "many" : "one"));
} else {
var11 = String.format(text2, var9);
name = "%s " + StatCollector.translateToLocal(displayItem.getUnlocalizedName() + ".name");
}
}

if (var5 >= var9)
var10.add(EnumChatFormatting.GRAY + "" + var11);
else
var10.add(EnumChatFormatting.RED + "" + var11);
var11 = String.format(name, var9);
var10.add((var5 >= var9 ? EnumChatFormatting.GRAY : EnumChatFormatting.RED) + var11);
}

if (var9 == 1)
var11 = I18n.format("container.enchant.level.one");
else
var11 = I18n.format("container.enchant.level.many", var9);
var11 = I18n.format(var9 == 1 ? "container.enchant.level.one" : "container.enchant.level.many", var9);

var10.add(EnumChatFormatting.GRAY + "" + var11);
var10.add(EnumChatFormatting.GRAY + var11);
}
}

Expand Down Expand Up @@ -327,4 +320,4 @@ public void func_147068_g() {
field_147081_y += (var5 - field_147081_y) * 0.9F;
field_147071_v += field_147081_y;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

public class ContainerEnchantment extends Container {

public static final Map<String, Integer> seeds = new HashMap<String, Integer>();
public static final Map<String, Integer> seeds = new HashMap<>();

/**
* SlotEnchantmentTable object with ItemStack to be enchanted
Expand All @@ -44,15 +44,12 @@ public class ContainerEnchantment extends Container {
public int[] enchantLevels;
public int[] field_178151_h;

public final boolean noFuel;

public ContainerEnchantment(InventoryPlayer inventory, World world, int x, int y, int z) {
tableInventory = new InventoryBasic("Enchant", true, 2) {

@Override
public int getInventoryStackLimit() {
return 64;
}

@Override
@Override
public void markDirty() {
super.markDirty();
ContainerEnchantment.this.onCraftMatrixChanged(this);
Expand All @@ -66,33 +63,33 @@ public void markDirty() {
field_178151_h = new int[]{-1, -1, -1};
this.world = world;
enchantmentSeed = getEnchantSeed(inventory.player);
addSlotToContainer(new Slot(tableInventory, 0, 15, 47) {
noFuel = EnchantingFuelRegistry.getFuels().isEmpty();
addSlotToContainer(new Slot(tableInventory, 0, noFuel ? 25 : 15, 47) {

@Override
public boolean isItemValid(ItemStack stack) {
return true;
}

@Override
@Override
public int getSlotStackLimit() {
return 1;
}
});
addSlotToContainer(new Slot(tableInventory, 1, 35, 47) {

@Override
public boolean isItemValid(ItemStack stack) {
return EnchantingFuelRegistry.isFuel(stack);
}
});
if (!noFuel) {
addSlotToContainer(new Slot(tableInventory, 1, 35, 47) {
@Override
public boolean isItemValid(ItemStack stack) {
return EnchantingFuelRegistry.isFuel(stack);
}
});
}
int var4;

for (var4 = 0; var4 < 3; ++var4)
for (int var5 = 0; var5 < 9; ++var5)
for (var4 = 0; var4 < 3; ++var4) {
for (int var5 = 0; var5 < 9; ++var5) {
addSlotToContainer(new Slot(inventory, var5 + var4 * 9 + 9, 8 + var5 * 18, 84 + var4 * 18));
}
}

for (var4 = 0; var4 < 9; ++var4)
for (var4 = 0; var4 < 9; ++var4) {
addSlotToContainer(new Slot(inventory, var4, 8 + var4 * 18, 142));
}
}

private static void setEnchantSeed(EntityPlayer player, int seed) {
Expand Down Expand Up @@ -174,14 +171,14 @@ public void onCraftMatrixChanged(IInventory p_75130_1_) {
for (j = -1; j <= 1; ++j)
for (int k = -1; k <= 1; ++k)
if ((j != 0 || k != 0) && world.isAirBlock(posX + k, posY, posZ + j) && world.isAirBlock(posX + k, posY + 1, posZ + j)) {
power += ForgeHooks.getEnchantPower(world, posX + k * 2, posY, posZ + j * 2);
power += ForgeHooks.getEnchantPower(world, posX + k * 2, posY + 1, posZ + j * 2);
power += (int) ForgeHooks.getEnchantPower(world, posX + k * 2, posY, posZ + j * 2);
power += (int) ForgeHooks.getEnchantPower(world, posX + k * 2, posY + 1, posZ + j * 2);

if (k != 0 && j != 0) {
power += ForgeHooks.getEnchantPower(world, posX + k * 2, posY, posZ + j);
power += ForgeHooks.getEnchantPower(world, posX + k * 2, posY + 1, posZ + j);
power += ForgeHooks.getEnchantPower(world, posX + k, posY, posZ + j * 2);
power += ForgeHooks.getEnchantPower(world, posX + k, posY + 1, posZ + j * 2);
power += (int) ForgeHooks.getEnchantPower(world, posX + k * 2, posY, posZ + j);
power += (int) ForgeHooks.getEnchantPower(world, posX + k * 2, posY + 1, posZ + j);
power += (int) ForgeHooks.getEnchantPower(world, posX + k, posY, posZ + j * 2);
power += (int) ForgeHooks.getEnchantPower(world, posX + k, posY + 1, posZ + j * 2);
}
}

Expand Down Expand Up @@ -278,7 +275,7 @@ private List<EnchantmentData> func_178148_a(ItemStack stack, int seed, int level

public int func_178147_e() {
ItemStack var1 = tableInventory.getStackInSlot(1);
return var1 == null ? 0 : var1.stackSize;
return var1 == null ? (noFuel ? Integer.MAX_VALUE : 0) : var1.stackSize;
}

/**
Expand Down Expand Up @@ -314,12 +311,12 @@ public ItemStack transferStackInSlot(EntityPlayer playerIn, int index) {
var3 = var5.copy();

if (index == 0) {
if (!mergeItemStack(var5, 2, 38, true))
if (!mergeItemStack(var5, 2, noFuel ? 37 : 38, true))
return null;
} else if (index == 1) {
} else if (!noFuel && index == 1) {
if (!mergeItemStack(var5, 2, 38, true))
return null;
} else if (EnchantingFuelRegistry.isFuel(var5)) {
} else if (!noFuel && EnchantingFuelRegistry.isFuel(var5)) {
if (!mergeItemStack(var5, 1, 2, true))
return null;
} else {
Expand Down

0 comments on commit 8c52c3a

Please sign in to comment.