diff --git a/src/main/java/gregtech/common/items/MetaItem1.java b/src/main/java/gregtech/common/items/MetaItem1.java index b57c4841680..6dd7d8bf4fa 100644 --- a/src/main/java/gregtech/common/items/MetaItem1.java +++ b/src/main/java/gregtech/common/items/MetaItem1.java @@ -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))); @@ -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)); diff --git a/src/main/java/gregtech/common/items/MetaItems.java b/src/main/java/gregtech/common/items/MetaItems.java index 4c579938d5e..a4fd11eb46d 100644 --- a/src/main/java/gregtech/common/items/MetaItems.java +++ b/src/main/java/gregtech/common/items/MetaItems.java @@ -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; diff --git a/src/main/java/gregtech/common/items/behaviors/ColorSprayBehaviour.java b/src/main/java/gregtech/common/items/behaviors/ColorSprayBehaviour.java index ab425239710..1457d27986f 100644 --- a/src/main/java/gregtech/common/items/behaviors/ColorSprayBehaviour.java +++ b/src/main/java/gregtech/common/items/behaviors/ColorSprayBehaviour.java @@ -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; @@ -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 @@ -49,6 +55,9 @@ public ActionResult 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); } @@ -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) { @@ -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 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)); } } diff --git a/src/main/java/gregtech/loaders/recipe/MachineRecipeLoader.java b/src/main/java/gregtech/loaders/recipe/MachineRecipeLoader.java index 022c4236ec8..e458ce8145a 100644 --- a/src/main/java/gregtech/loaders/recipe/MachineRecipeLoader.java +++ b/src/main/java/gregtech/loaders/recipe/MachineRecipeLoader.java @@ -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() diff --git a/src/main/resources/assets/gregtech/lang/en_us.lang b/src/main/resources/assets/gregtech/lang/en_us.lang index 7e287434839..4e2bd39158e 100644 --- a/src/main/resources/assets/gregtech/lang/en_us.lang +++ b/src/main/resources/assets/gregtech/lang/en_us.lang @@ -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) @@ -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 diff --git a/src/main/resources/assets/gregtech/models/item/metaitems/spray.solvent.json b/src/main/resources/assets/gregtech/models/item/metaitems/spray.solvent.json new file mode 100644 index 00000000000..56870fa6c67 --- /dev/null +++ b/src/main/resources/assets/gregtech/models/item/metaitems/spray.solvent.json @@ -0,0 +1,6 @@ +{ + "parent": "item/generated", + "textures": { + "layer0": "gregtech:items/metaitems/spray.solvent" + } +} diff --git a/src/main/resources/assets/gregtech/textures/items/metaitems/spray.solvent.png b/src/main/resources/assets/gregtech/textures/items/metaitems/spray.solvent.png new file mode 100644 index 00000000000..f2e1024e071 Binary files /dev/null and b/src/main/resources/assets/gregtech/textures/items/metaitems/spray.solvent.png differ