Skip to content

Commit

Permalink
Add Spray Can (Solvent) to remove paint (#704)
Browse files Browse the repository at this point in the history
  • Loading branch information
serenibyss authored Feb 26, 2022
1 parent 428f8f9 commit ee5d83b
Show file tree
Hide file tree
Showing 7 changed files with 115 additions and 4 deletions.
8 changes: 6 additions & 2 deletions src/main/java/gregtech/common/items/MetaItem1.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public void registerSubItems() {
SHAPE_MOLDS[11] = SHAPE_MOLD_GEAR_SMALL = addItem(23, "shape.mold.gear.small").setMaterialInfo(new ItemMaterialInfo(new MaterialStack(Materials.Steel, M * 4)));
SHAPE_MOLDS[12] = SHAPE_MOLD_ROTOR = addItem(24, "shape.mold.rotor").setMaterialInfo(new ItemMaterialInfo(new MaterialStack(Materials.Steel, M * 4)));

// Extruder Shapes: ID 31-60
// Extruder Shapes: ID 31-59
SHAPE_EXTRUDERS[0] = SHAPE_EXTRUDER_PLATE = addItem(31, "shape.extruder.plate").setMaterialInfo(new ItemMaterialInfo(new MaterialStack(Materials.Steel, M * 4)));
SHAPE_EXTRUDERS[1] = SHAPE_EXTRUDER_ROD = addItem(32, "shape.extruder.rod").setMaterialInfo(new ItemMaterialInfo(new MaterialStack(Materials.Steel, M * 4)));
SHAPE_EXTRUDERS[2] = SHAPE_EXTRUDER_BOLT = addItem(33, "shape.extruder.bolt").setMaterialInfo(new ItemMaterialInfo(new MaterialStack(Materials.Steel, M * 4)));
Expand Down Expand Up @@ -104,10 +104,14 @@ public void registerSubItems() {
SHAPE_EXTRUDERS[25] = SHAPE_EXTRUDER_ROD_LONG = addItem(56, "shape.extruder.rod_long").setMaterialInfo(new ItemMaterialInfo(new MaterialStack(Materials.Steel, M * 4)));
SHAPE_EXTRUDERS[26] = SHAPE_EXTRUDER_ROTOR = addItem(57, "shape.extruder.rotor").setMaterialInfo(new ItemMaterialInfo(new MaterialStack(Materials.Steel, M * 4)));

// Spray Cans: ID 61-77
// Spray Cans: ID 60-77
SPRAY_EMPTY = addItem(61, "spray.empty")
.setMaterialInfo(new ItemMaterialInfo(new MaterialStack(Materials.Tin, M * 2), new MaterialStack(Materials.Redstone, M)));

// out of registry order so it can reference the Empty Spray Can
SPRAY_SOLVENT = addItem(60, "spray.solvent").setMaxStackSize(1)
.addComponents(new ColorSprayBehaviour(SPRAY_EMPTY.getStackForm(), 1024, -1));

for (int i = 0; i < EnumDyeColor.values().length; i++) {
SPRAY_CAN_DYES[i] = addItem(62 + i, "spray.can.dyes." + EnumDyeColor.values()[i].getName()).setMaxStackSize(1)
.addComponents(new ColorSprayBehaviour(SPRAY_EMPTY.getStackForm(), 512, i));
Expand Down
1 change: 1 addition & 0 deletions src/main/java/gregtech/common/items/MetaItems.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ private MetaItems() {
public static MetaItem<?>.MetaValueItem SHAPE_EXTRUDER_ROD_LONG;
public static MetaItem<?>.MetaValueItem SHAPE_EXTRUDER_ROTOR;

public static MetaItem<?>.MetaValueItem SPRAY_SOLVENT;
public static MetaItem<?>.MetaValueItem SPRAY_EMPTY;

public static MetaItem<?>.MetaValueItem FLUID_CELL;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,15 @@
import appeng.api.util.AEColor;
import appeng.tile.networking.TileCableBus;
import gregtech.api.GTValues;
import gregtech.api.metatileentity.MetaTileEntity;
import gregtech.api.metatileentity.MetaTileEntityHolder;
import gregtech.api.pipenet.tile.IPipeTile;
import gregtech.api.sound.GTSounds;
import net.minecraft.block.Block;
import net.minecraft.block.BlockColored;
import net.minecraft.block.BlockStainedGlass;
import net.minecraft.block.BlockStainedGlassPane;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.player.EntityPlayer;
Expand All @@ -29,7 +34,8 @@ public class ColorSprayBehaviour extends AbstractUsableBehaviour {
public ColorSprayBehaviour(ItemStack empty, int totalUses, int color) {
super(totalUses);
this.empty = empty;
this.color = EnumDyeColor.values()[color];
EnumDyeColor[] colors = EnumDyeColor.values();
this.color = color >= colors.length || color < 0 ? null : colors[color];
}

@Override
Expand All @@ -49,6 +55,9 @@ public ActionResult<ItemStack> onItemUse(EntityPlayer player, World world, Block
private boolean tryPaintBlock(EntityPlayer player, World world, BlockPos pos, EnumFacing side) {
IBlockState blockState = world.getBlockState(pos);
Block block = blockState.getBlock();
if (color == null) {
return tryStripBlockColor(player, world, pos, block, side);
}
return block.recolorBlock(world, pos, side, this.color) || tryPaintSpecialBlock(player, world, pos, block);
}

Expand All @@ -65,6 +74,12 @@ private boolean tryPaintSpecialBlock(EntityPlayer player, World world, BlockPos
world.setBlockState(pos, newBlockState);
return true;
}
if (block == Blocks.HARDENED_CLAY) {
IBlockState newBlockState = Blocks.STAINED_HARDENED_CLAY.getDefaultState()
.withProperty(BlockColored.COLOR, this.color);
world.setBlockState(pos, newBlockState);
return true;
}
if (Loader.isModLoaded(GTValues.MODID_APPENG)) {
TileEntity te = world.getTileEntity(pos);
if (te instanceof TileCableBus) {
Expand All @@ -79,10 +94,86 @@ private boolean tryPaintSpecialBlock(EntityPlayer player, World world, BlockPos
return false;
}

@SuppressWarnings("unchecked, rawtypes")
private boolean tryStripBlockColor(EntityPlayer player, World world, BlockPos pos, Block block, EnumFacing side) {
// MC special cases
if (block == Blocks.STAINED_GLASS) {
world.setBlockState(pos, Blocks.GLASS.getDefaultState());
return true;
}
if (block == Blocks.STAINED_GLASS_PANE) {
world.setBlockState(pos, Blocks.GLASS_PANE.getDefaultState());
return true;
}
if (block == Blocks.STAINED_HARDENED_CLAY) {
world.setBlockState(pos, Blocks.HARDENED_CLAY.getDefaultState());
return true;
}

// MTE special case
TileEntity te = world.getTileEntity(pos);
if (te instanceof MetaTileEntityHolder) {
MetaTileEntity mte = ((MetaTileEntityHolder) te).getMetaTileEntity();
if (mte != null) {
if (mte.isPainted()) {
mte.setPaintingColor(-1);
return true;
} else return false;
}
}

// TileEntityPipeBase special case
if (te instanceof IPipeTile) {
IPipeTile<?, ?> pipe = (IPipeTile<?, ?>) te;
if (pipe.isPainted()) {
pipe.setPaintingColor(-1);
return true;
} else return false;
}

// AE2 cable special case
if (Loader.isModLoaded(GTValues.MODID_APPENG)) {
if (te instanceof TileCableBus) {
TileCableBus cable = (TileCableBus) te;
// do not try to strip color if it is already colorless
if (cable.getColor() != AEColor.TRANSPARENT) {
cable.recolourBlock(null, AEColor.TRANSPARENT, player);
return true;
} else return false;
}
}

// General case
IBlockState state = world.getBlockState(pos);
for (IProperty prop : state.getProperties().keySet()) {
if (prop.getName().equals("color") && prop.getValueClass() == EnumDyeColor.class) {
IBlockState defaultState = block.getDefaultState();
EnumDyeColor defaultColor = EnumDyeColor.WHITE;
try {
// try to read the default color value from the default state instead of just
// blindly setting it to default state, and potentially resetting other values
defaultColor = (EnumDyeColor) defaultState.getValue(prop);
} catch (IllegalArgumentException ignored) {
// no default color, we may have to fallback to WHITE here
// other mods that have custom behavior can be done as
// special cases above on a case-by-case basis
}
block.recolorBlock(world, pos, side, defaultColor);
return true;
}
}

return false;
}

@Override
public void addInformation(ItemStack itemStack, List<String> lines) {
int remainingUses = getUsesLeft(itemStack);
lines.add(I18n.format("behaviour.paintspray." + this.color.getTranslationKey() + ".tooltip"));
if (color != null) {
lines.add(I18n.format("behaviour.paintspray." + this.color.getTranslationKey() + ".tooltip"));
} else {
lines.add(I18n.format("behaviour.paintspray.solvent.tooltip"));
}
lines.add(I18n.format("behaviour.paintspray.uses", remainingUses));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,13 @@ private static void registerAssemblerRecipes() {
.buildAndRegister();
}

CANNER_RECIPES.recipeBuilder()
.input(SPRAY_EMPTY)
.fluidInputs(Acetone.getFluid(1000))
.output(SPRAY_SOLVENT)
.EUt(VA[ULV]).duration(200)
.buildAndRegister();

Material material = Materials.Iron;

RecipeMaps.ASSEMBLER_RECIPES.recipeBuilder()
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/assets/gregtech/lang/en_us.lang
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ metaitem.large_fluid_cell.stainless_steel.name=%s Stainless Steel Cell
metaitem.large_fluid_cell.titanium.name=%s Titanium Cell
metaitem.large_fluid_cell.tungstensteel.name=%s Tungstensteel Cell

metaitem.spray.solvent.name=Spray Can (Solvent)
metaitem.spray.can.dyes.white.name=Spray Can (White)
metaitem.spray.can.dyes.orange.name=Spray Can (Orange)
metaitem.spray.can.dyes.magenta.name=Spray Can (Magenta)
Expand Down Expand Up @@ -3866,6 +3867,7 @@ behaviour.softhammer=Activates and Deactivates Machines
behaviour.hammer=Turns on and off Muffling for Machines (by hitting them)
behaviour.wrench=Rotates Blocks on Rightclick
behaviour.boor.by=by %s
behaviour.paintspray.solvent.tooltip=Can remove color from things
behaviour.paintspray.white.tooltip=Can paint things in White
behaviour.paintspray.orange.tooltip=Can paint things in Orange
behaviour.paintspray.magenta.tooltip=Can paint things in Magenta
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"parent": "item/generated",
"textures": {
"layer0": "gregtech:items/metaitems/spray.solvent"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit ee5d83b

Please sign in to comment.