Allow creative color applicator use (#1576)

This commit is contained in:
Worive authored and GitHub committed 2026-09-20 15:57:36 +02:00
1 parent 3640653615
commit fdedc3a8f0
4 files changed
+66 -23

No files matched your search

@@ -74,7 +74,7 @@ public class GuiColorSelect extends GuiScreen {
AEColor activeColor;
if (held != null && held.getItem() instanceof ToolColorApplicator applicator) {
availableColors = applicator.getAvailableColorsCount(held);
availableColors = applicator.getAvailableColorsCount(held, this.player.capabilities.isCreativeMode);
activeColor = applicator.getActiveColor(held);
} else {
availableColors = Collections.emptyMap();
@@ -90,7 +90,7 @@ public class PacketValueConfig extends AppEngPacket {
&& player.getHeldItem().getItem() instanceof IMouseWheelItem) {
final ItemStack is = player.getHeldItem();
final IMouseWheelItem si = (IMouseWheelItem) is.getItem();
si.onWheel(is, this.Value.equals("WheelUp"));
si.onWheel(player, is, this.Value.equals("WheelUp"));
} else if (this.Name.equals("CPUTable.Cpu.Set") && c instanceof final ICraftingCPUSelectorContainer qk) {
qk.selectCPU(Integer.parseInt(this.Value));
} else if (this.Name.equals("Terminal.StartWithFollow") && c instanceof final ContainerCraftConfirm qk) {
@@ -17,5 +17,9 @@ public interface IMouseWheelItem {
void onWheel(ItemStack is, boolean up);
default void onWheel(EntityPlayer player, ItemStack is, boolean up) {
this.onWheel(is, up);
}
void onWheelClick(EntityPlayer player, ItemStack is);
}
@@ -13,6 +13,7 @@ package appeng.items.tools.powered;
import static appeng.util.item.AEItemStackType.ITEM_STACK_TYPE;
import java.util.Collections;
import java.util.EnumMap;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.LinkedList;
@@ -25,6 +26,7 @@ import net.minecraft.block.BlockDispenser;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemSnowball;
import net.minecraft.item.ItemStack;
@@ -162,6 +164,7 @@ public class ToolColorApplicator extends AEBasePoweredItem
final int y, final int z, final int side, final float hitX, final float hitY, final float hitZ) {
int trueX = x, trueY = y, trueZ = z;
boolean usingOffhand = false;
final boolean creative = player.capabilities.isCreativeMode;
if (Platform.isBackhandLoaded) {
if (handleOffhand(stack, player, world, x, y, z, side, hitX, hitY, hitZ)) {
@@ -181,13 +184,13 @@ public class ToolColorApplicator extends AEBasePoweredItem
return false;
}
if (this.getAECurrentPower(stack) < POWER_PER_USE) {
if (!creative && this.getAECurrentPower(stack) < POWER_PER_USE) {
return false;
}
final IMEInventory<IAEItemStack> inv = AEApi.instance().registries().cell()
.getCellInventory(stack, null, StorageChannel.ITEMS);
if (inv == null) {
if (!creative && inv == null) {
return false;
}
@@ -197,14 +200,16 @@ public class ToolColorApplicator extends AEBasePoweredItem
}
activeConfig.stackSize = 1;
final IAEItemStack extractedSim = inv
.extractItems(AEItemStack.create(activeConfig), Actionable.SIMULATE, new BaseActionSource());
if (extractedSim == null) {
return false;
ItemStack paintSource = activeConfig;
if (!creative) {
final IAEItemStack extractedSim = inv
.extractItems(AEItemStack.create(activeConfig), Actionable.SIMULATE, new BaseActionSource());
if (extractedSim == null) {
return false;
}
paintSource = extractedSim.getItemStack();
}
ItemStack paintSource = extractedSim.getItemStack();
AEColor paintColor = this.getColorFromItem(paintSource);
TileEntity targetTe = world.getTileEntity(trueX, trueY, trueZ);
@@ -219,13 +224,15 @@ public class ToolColorApplicator extends AEBasePoweredItem
}
if (success) {
inv.extractItems(AEItemStack.create(paintSource), Actionable.MODULATE, new BaseActionSource());
this.extractAEPower(stack, POWER_PER_USE);
if (!creative) {
inv.extractItems(AEItemStack.create(paintSource), Actionable.MODULATE, new BaseActionSource());
this.extractAEPower(stack, POWER_PER_USE);
final IAEItemStack newStack = inv
.extractItems(AEItemStack.create(activeConfig), Actionable.SIMULATE, new BaseActionSource());
if (newStack == null) {
this.cycleColors(stack, this.getColor(stack), 1);
final IAEItemStack newStack = inv
.extractItems(AEItemStack.create(activeConfig), Actionable.SIMULATE, new BaseActionSource());
if (newStack == null) {
this.cycleColors(stack, this.getColor(stack), 1);
}
}
// Retuning false when using offhand means only the normal hand animation will play
@@ -337,6 +344,10 @@ public class ToolColorApplicator extends AEBasePoweredItem
}
public ItemStack getColor(final ItemStack is) {
return this.getColor(is, false);
}
private ItemStack getColor(final ItemStack is, final boolean creative) {
final NBTTagCompound c = is.getTagCompound();
if (c != null && c.hasKey(NBT_COLOR)) {
final NBTTagCompound color = c.getCompoundTag(NBT_COLOR);
@@ -345,7 +356,12 @@ public class ToolColorApplicator extends AEBasePoweredItem
return oldColor;
}
}
return this.findNextColor(is, null, 0);
return creative ? this.getColorStack(AEColor.Transparent) : this.findNextColor(is, null, 0);
}
private ItemStack getColorStack(final AEColor color) {
return color == AEColor.Transparent ? new ItemStack(Items.snowball)
: AEApi.instance().definitions().items().coloredPaintBall().stack(color, 1);
}
private ItemStack findNextColor(final ItemStack is, final ItemStack anchor, final int scrollOffset) {
@@ -404,12 +420,7 @@ public class ToolColorApplicator extends AEBasePoweredItem
}
public void setColor(final ItemStack is, final AEColor newColor) {
if (newColor == AEColor.Transparent) {
setColor(is, (ItemStack) null);
} else {
final ItemStack paintBall = AEApi.instance().definitions().items().coloredPaintBall().stack(newColor, 1);
setColor(is, paintBall);
}
this.setColor(is, this.getColorStack(newColor));
}
private void setColor(final ItemStack is, final ItemStack newColor) {
@@ -468,6 +479,16 @@ public class ToolColorApplicator extends AEBasePoweredItem
}
public void cycleColors(final ItemStack is, final ItemStack paintBall, final int i) {
this.cycleColors(is, paintBall, i, false);
}
private void cycleColors(final ItemStack is, final ItemStack paintBall, final int i, final boolean creative) {
if (creative) {
final AEColor color = this.getColorFromItem(paintBall);
this.setColor(is, AEColor.fromOrdinal(Math.floorMod(color.ordinal() + i, AEColor.VALUES.length)));
return;
}
if (paintBall == null) {
this.setColor(is, this.getColor(is));
} else {
@@ -476,6 +497,18 @@ public class ToolColorApplicator extends AEBasePoweredItem
}
public Map<AEColor, Long> getAvailableColorsCount(ItemStack stack) {
return this.getAvailableColorsCount(stack, false);
}
public Map<AEColor, Long> getAvailableColorsCount(ItemStack stack, boolean creative) {
if (creative) {
final Map<AEColor, Long> availableColors = new EnumMap<>(AEColor.class);
for (final AEColor color : AEColor.VALUES) {
availableColors.put(color, 1L);
}
return availableColors;
}
if (this.getAECurrentPower(stack) <= 0) {
return Collections.emptyMap();
}
@@ -635,6 +668,12 @@ public class ToolColorApplicator extends AEBasePoweredItem
this.cycleColors(is, this.getColor(is), up ? 1 : -1);
}
@Override
public void onWheel(final EntityPlayer player, final ItemStack is, final boolean up) {
final boolean creative = player.capabilities.isCreativeMode;
this.cycleColors(is, this.getColor(is, creative), up ? 1 : -1, creative);
}
@Override
public void onWheelClick(EntityPlayer player, ItemStack is) {
if (!player.worldObj.isRemote) {