-
Notifications
You must be signed in to change notification settings - Fork 208
Spray can refactor and creative spray can #2858
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Zorbatron
wants to merge
111
commits into
master
Choose a base branch
from
zb/spray-can-refactor-and-creative-spray-can
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 91 commits
Commits
Show all changes
111 commits
Select commit
Hold shift + click to select a range
5731a0e
Refactor spray can class for more modularity
Zorbatron c1e7048
Fix toolbelt code I forgot to change
Zorbatron 3201860
Accidentally doubled the durability of spray cans
Zorbatron 65da208
Fix oversight from PR #2712 where the non tool (wrenches, hammers, et…
Zorbatron 3c28b0c
javadoc wording change
Zorbatron 2caa104
add some NotNulls to ToolHelper
Zorbatron 718db87
add some ItemStack#isEmpty checks in ToolHelper
Zorbatron 01427d7
Add javadoc to AbstractSprayBehavior#getColor
Zorbatron 14196d8
Working creative spray can prototype
Zorbatron a903f90
Shuffle/dedup some code
Zorbatron 4f0822b
fogor sound
Zorbatron e463e55
Add textures (ctrl c + v of the gtnh creative spray can)
Zorbatron 9243577
Basic lang
Zorbatron b7040b1
Lang but good
Zorbatron ea13f6e
Add a way for MetaItems to handle MouseEvents and add some pattern ma…
Zorbatron f445deb
Implement generic mouse event packet handling for meta items
Zorbatron 5de3445
Add javadocs to PacketItemMouseEvent describing what each value means.
Zorbatron 34628ca
Add line about -1 = no click
Zorbatron d674ebc
Precheck if there is no held item in onMouseEvent
Zorbatron f94aaf4
Have the default handleMouseEventClient impl send the packet if only …
Zorbatron fca8000
Make handleMouseEventClient not have a default
Zorbatron 7133c23
Forgot to remove comment after removing default impl
Zorbatron 5ff6d73
Mention how MouseEvents are spammed when looking around
Zorbatron 113d955
lang error
Zorbatron 1b1619d
Make the packet handling not bad
Zorbatron c8b59ec
un bork the packet copying
Zorbatron 851cb25
Don't allow changing the color if it's locked
Zorbatron a6abf20
Re-add comment I accidentally deleted when moving code around
Zorbatron bdfe101
Add overload to MTE#setPaintingColor with EnumFacing
Zorbatron dd4fd04
Support all AE2 tiles instead of only cables and redo mouse logic
Zorbatron 8c19545
shrink color button icon a smidge. Fix gui not opening when looking a…
Zorbatron c30c3dd
Fix spray cans being able to spray with no durability left
Zorbatron accbb27
Refactor how coloring is done based on GT5u's method
Zorbatron a6678e9
Use the new coloring method to get the color when middle-clicking wit…
Zorbatron ce7574e
Implement AE2 color container
Zorbatron 6a4c5b5
Match the order of methods, because uh yea
Zorbatron 58db4c7
Add missing some missing `true` early returns
Zorbatron 8d852dd
Implement GT color container
Zorbatron 0f52484
Don't color stuff if it's already that color
Zorbatron e6891ee
Use ColoredBlockContainer#isValid in the spray method
Zorbatron a706545
Add DurabilitySprayBehavior constructor shortcut
Zorbatron 23155ae
Move the color stuff out of the util package
Zorbatron 7e56422
Make durability cans take durability again
Zorbatron 78a2af0
Not there!!!
Zorbatron 9a81375
spoble
Zorbatron e33bf94
Absorb #2368 pt1
Zorbatron 9664e91
Change some values in case the pipe walker doesn't hit any pipes
Zorbatron d23c871
Ignore copying the color if the hit color is the same as the can already
Zorbatron f680894
ugh stuffffff :((, it isn't breaking at 0??????????
Zorbatron 7f0ce7c
Fix not breaking on empty, breaking when recursive painting it still …
Zorbatron ccb059f
Use Predicate instead of "BooleanFunction" (what was I doing bruh)
Zorbatron b0b8767
No need to null check here
Zorbatron 80db4d2
Misc static analysis changes
Zorbatron 164ddaa
Fix replacing with empty can when depleted
Zorbatron 74bd2bc
Try to stop at a branch
Zorbatron afdef14
Prevent recursive spraying if the pipe unpainted and the can is solvent
Zorbatron 0ca0466
formatting changes
Zorbatron 8784a96
Remove debug logger
Zorbatron a9a8bfa
spobl
Zorbatron 2f05b94
Close the color picker gui when color pressed
Zorbatron ae48a1f
Cancel subwalkers at a split
Zorbatron ec0e4ec
Make spray cans show the grid overlay when sneaking
Zorbatron ecb4dcc
Allow setting ARBG ints in color containers.
Zorbatron b098157
Use a custom pipe traversal method as PipeNetWalker doesn't fit my ne…
Zorbatron 6f5aafb
Make the ray trace not die server side (ie ACTUALLY WORK)
Zorbatron 63fa2de
Fix using 1 durability too less on recursive paints
Zorbatron 6834dcc
Add config for max spray distance
Zorbatron 12ddcf1
Remove left clicking to shift the creative spray cans color
Zorbatron c1df493
Tiny color container refactor
Zorbatron afed92e
Remove redundant check (The AE2 color manager won't be registered in …
Zorbatron cede48d
spotless
Zorbatron dc3c013
Remove locking after removing the left click functionality
Zorbatron 884ccde
No more spellchecking!!!
Zorbatron 82f22a4
Merge branch 'master' into zb/spray-can-refactor-and-creative-spray-can
Zorbatron 59ec199
Make color containers more static, less object creation
Zorbatron 1becdaa
Constant not needed after I added the spray range config
Zorbatron cdd102b
Add message to null check
Zorbatron 3e0410d
Prep ARGB support in the creative can
Zorbatron da9cb66
Slight event handler refactor
Zorbatron deb32a7
Add basic (A)RGB support to the creative can
Zorbatron ef55e11
Use `onItemUseFirst` instead of `onItemUse` for spraying
Zorbatron f8a5c0b
Undo accidental renaming
Zorbatron 5efbdce
Add a couple methods to ColorUtil
Zorbatron 71e7b1b
Simplify item stack color method
Zorbatron f6d114b
Add slider widgets for RGB mode
Zorbatron 81cbeaf
Put hex color in item name when in RGB mode
Zorbatron 95ad952
Use tabs to separate normal and RGB mode
Zorbatron 7b99a78
Make the slider have a background (it changes color!)
Zorbatron 34d346f
Remove old and completed TODO
Zorbatron 999ab26
fix tooltip saying green is blue and blue is green
Zorbatron b3b9a72
Correct small error in ColorUtil javadoc
Zorbatron 89c6900
Formatting
Zorbatron 0fdb487
Merge branch 'master' into zb/spray-can-refactor-and-creative-spray-can
Zorbatron 0f79f18
Post merge fixes
Zorbatron 24ef97a
Remove custom widgets as updating mui2 solved the reason I needed them
Zorbatron dac0122
Less privates
Zorbatron 3da35f5
Fix not being able to recolor plain vanilla blocks
Zorbatron 6a8106c
spootless
Zorbatron 1bf4015
Return the result of world.setBlockState
Zorbatron d9ef4cf
Unbreak half of the vanilla blocks
Zorbatron 64220b1
Rename isValid method
Zorbatron 5c2a130
Add spray can support to beds
Zorbatron 4bb82be
Require `ColoredBlockContainer`s to have a ResourceLocation ID
Zorbatron 60e58a4
fix build error due to skill issue
Zorbatron 6cfb27c
Fix bed spraying from a tool belt
Zorbatron b493fbf
WIP stuff
Zorbatron 800f3e3
wrong message
Zorbatron ebc3d29
Finish WIP, refactor how containers support dye or argb
Zorbatron 86a8dae
Swap error messages
Zorbatron 58885a0
Actually clear NBT when spray can breaks
Zorbatron 6b03db6
Use nbt constant for MUI2 sync too
Zorbatron File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
src/main/java/gregtech/api/color/ColoredBlockContainer.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| package gregtech.api.color; | ||
|
|
||
| import gregtech.api.color.containers.AE2ColorContainer; | ||
| import gregtech.api.color.containers.GTPipeColorContainer; | ||
| import gregtech.api.color.containers.MTEColorContainer; | ||
| import gregtech.api.color.containers.NullColorContainer; | ||
| import gregtech.api.color.containers.VanillaColorContainer; | ||
| import gregtech.api.util.Mods; | ||
|
|
||
| import net.minecraft.entity.player.EntityPlayer; | ||
| import net.minecraft.item.EnumDyeColor; | ||
| import net.minecraft.util.EnumFacing; | ||
| import net.minecraft.util.math.BlockPos; | ||
| import net.minecraft.world.World; | ||
|
|
||
| import it.unimi.dsi.fastutil.objects.ObjectArraySet; | ||
| import org.jetbrains.annotations.ApiStatus; | ||
| import org.jetbrains.annotations.NotNull; | ||
| import org.jetbrains.annotations.Nullable; | ||
|
|
||
| import java.util.Objects; | ||
| import java.util.Set; | ||
|
|
||
| /** | ||
| * Used to provide a consistent interface for dealing with colored blocks, whether vanilla or modded. <br/> | ||
| * Inspired by GT5u's <a href= | ||
| * "https://github.com/GTNewHorizons/GT5-Unofficial/blob/7ba0fc903e5d14928d2b894b00a7b7dfc65eee18/src/main/java/gregtech/api/util/ColoredBlockContainer.java">ColoredBlockContainer</a> | ||
| */ | ||
| public abstract class ColoredBlockContainer { | ||
|
|
||
| @NotNull | ||
| private static final Set<ColoredBlockContainer> CONTAINERS = new ObjectArraySet<>(4); | ||
|
|
||
| public static void registerContainer(@NotNull ColoredBlockContainer container) { | ||
| CONTAINERS.add(Objects.requireNonNull(container, "A null ColoredBlockContainer cannot be registered!")); | ||
| } | ||
|
|
||
| public static @NotNull ColoredBlockContainer getContainer(@NotNull World world, @NotNull BlockPos pos, | ||
| @NotNull EnumFacing facing, | ||
| @NotNull EntityPlayer player) { | ||
| for (ColoredBlockContainer container : CONTAINERS) { | ||
| if (container.isValid(world, pos, facing, player)) { | ||
| return container; | ||
| } | ||
| } | ||
|
|
||
| return NullColorContainer.NULL_CONTAINER; | ||
| } | ||
|
|
||
| @ApiStatus.Internal | ||
| public static void registerCEuContainers() { | ||
| registerContainer(new GTPipeColorContainer()); | ||
| registerContainer(new MTEColorContainer()); | ||
| if (Mods.AppliedEnergistics2.isModLoaded()) { | ||
| registerContainer(new AE2ColorContainer()); | ||
| } | ||
| registerContainer(new VanillaColorContainer()); | ||
| } | ||
|
|
||
| public abstract boolean isValid(@NotNull World world, @NotNull BlockPos pos, @NotNull EnumFacing facing, | ||
| @NotNull EntityPlayer player); | ||
|
|
||
| public abstract boolean setColor(@NotNull World world, @NotNull BlockPos pos, @NotNull EnumFacing facing, | ||
| @NotNull EntityPlayer player, @Nullable EnumDyeColor newColor); | ||
|
|
||
| public boolean setColor(@NotNull World world, @NotNull BlockPos pos, @NotNull EnumFacing facing, | ||
| @NotNull EntityPlayer player, int newColor) { | ||
| return false; | ||
| } | ||
|
|
||
| public abstract boolean removeColor(@NotNull World world, @NotNull BlockPos pos, @NotNull EnumFacing facing, | ||
| @NotNull EntityPlayer player); | ||
|
|
||
| public abstract @Nullable EnumDyeColor getColor(@NotNull World world, @NotNull BlockPos pos, | ||
| @NotNull EnumFacing facing, @NotNull EntityPlayer player); | ||
|
|
||
| public int getColorInt(@NotNull World world, @NotNull BlockPos pos, @NotNull EnumFacing facing, | ||
| @NotNull EntityPlayer player) { | ||
| EnumDyeColor dyeColor = getColor(world, pos, facing, player); | ||
| return dyeColor == null ? -1 : dyeColor.colorValue; | ||
| } | ||
|
|
||
| public boolean colorMatches(@NotNull World world, @NotNull BlockPos pos, @NotNull EnumFacing facing, | ||
| @NotNull EntityPlayer player, @Nullable EnumDyeColor color) { | ||
| return getColor(world, pos, facing, player) == color; | ||
| } | ||
|
|
||
| public boolean colorMatches(@NotNull World world, @NotNull BlockPos pos, @NotNull EnumFacing facing, | ||
| @NotNull EntityPlayer player, int color) { | ||
| return getColorInt(world, pos, facing, player) == color; | ||
| } | ||
|
|
||
| public boolean supportsARGB() { | ||
| return false; | ||
| } | ||
| } | ||
69 changes: 69 additions & 0 deletions
69
src/main/java/gregtech/api/color/containers/AE2ColorContainer.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| package gregtech.api.color.containers; | ||
|
|
||
| import gregtech.api.color.ColoredBlockContainer; | ||
|
|
||
| import net.minecraft.entity.player.EntityPlayer; | ||
| import net.minecraft.item.EnumDyeColor; | ||
| import net.minecraft.tileentity.TileEntity; | ||
| import net.minecraft.util.EnumFacing; | ||
| import net.minecraft.util.math.BlockPos; | ||
| import net.minecraft.world.World; | ||
|
|
||
| import appeng.api.implementations.tiles.IColorableTile; | ||
| import appeng.api.util.AEColor; | ||
| import org.jetbrains.annotations.NotNull; | ||
| import org.jetbrains.annotations.Nullable; | ||
|
|
||
| public class AE2ColorContainer extends ColoredBlockContainer { | ||
|
|
||
| @Override | ||
| public boolean setColor(@NotNull World world, @NotNull BlockPos pos, @NotNull EnumFacing facing, | ||
| @NotNull EntityPlayer player, @Nullable EnumDyeColor newColor) { | ||
| if (newColor == null) { | ||
| return removeColor(world, pos, facing, player); | ||
| } | ||
|
|
||
| if (getColor(world, pos, facing, player) == newColor) { | ||
| return false; | ||
| } | ||
|
|
||
| TileEntity te = world.getTileEntity(pos); | ||
| if (te instanceof IColorableTile colorableTile) { | ||
| if (colorableTile.getColor().dye != newColor) { | ||
| colorableTile.recolourBlock(facing, AEColor.values()[newColor.ordinal()], player); | ||
|
Zorbatron marked this conversation as resolved.
Outdated
|
||
| return true; | ||
| } | ||
| } | ||
|
|
||
| return false; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean removeColor(@NotNull World world, @NotNull BlockPos pos, @NotNull EnumFacing facing, | ||
| @NotNull EntityPlayer player) { | ||
| TileEntity te = world.getTileEntity(pos); | ||
| if (te instanceof IColorableTile colorableTile && colorableTile.getColor() != AEColor.TRANSPARENT) { | ||
| colorableTile.recolourBlock(facing, AEColor.TRANSPARENT, player); | ||
| return true; | ||
| } | ||
|
|
||
| return false; | ||
| } | ||
|
|
||
| @Override | ||
| public @Nullable EnumDyeColor getColor(@NotNull World world, @NotNull BlockPos pos, @NotNull EnumFacing facing, | ||
| @NotNull EntityPlayer player) { | ||
| TileEntity te = world.getTileEntity(pos); | ||
| if (te instanceof IColorableTile colorableTile) { | ||
| return colorableTile.getColor().dye; | ||
| } | ||
|
|
||
| return null; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean isValid(@NotNull World world, @NotNull BlockPos pos, @NotNull EnumFacing facing, | ||
| @NotNull EntityPlayer player) { | ||
| return world.getTileEntity(pos) instanceof IColorableTile; | ||
| } | ||
| } | ||
93 changes: 93 additions & 0 deletions
93
src/main/java/gregtech/api/color/containers/GTPipeColorContainer.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| package gregtech.api.color.containers; | ||
|
|
||
| import gregtech.api.color.ColoredBlockContainer; | ||
| import gregtech.api.pipenet.tile.IPipeTile; | ||
| import gregtech.api.util.ColorUtil; | ||
|
|
||
| import net.minecraft.entity.player.EntityPlayer; | ||
| import net.minecraft.item.EnumDyeColor; | ||
| import net.minecraft.util.EnumFacing; | ||
| import net.minecraft.util.math.BlockPos; | ||
| import net.minecraft.world.World; | ||
|
|
||
| import org.jetbrains.annotations.NotNull; | ||
| import org.jetbrains.annotations.Nullable; | ||
|
|
||
| public class GTPipeColorContainer extends ColoredBlockContainer { | ||
|
|
||
| @Override | ||
| public boolean setColor(@NotNull World world, @NotNull BlockPos pos, @NotNull EnumFacing facing, | ||
| @NotNull EntityPlayer player, @Nullable EnumDyeColor newColor) { | ||
| if (newColor == null) { | ||
| return removeColor(world, pos, facing, player); | ||
| } | ||
|
|
||
| if (getColorInt(world, pos, facing, player) == newColor.colorValue) { | ||
| return false; | ||
| } | ||
|
|
||
| if (world.getTileEntity(pos) instanceof IPipeTile<?, ?>pipeTile) { | ||
| pipeTile.setPaintingColor(newColor.colorValue); | ||
| return true; | ||
| } | ||
|
|
||
| return false; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean setColor(@NotNull World world, @NotNull BlockPos pos, @NotNull EnumFacing facing, | ||
| @NotNull EntityPlayer player, int newColor) { | ||
| if (newColor == -1) { | ||
| return removeColor(world, pos, facing, player); | ||
| } | ||
|
|
||
| if (world.getTileEntity(pos) instanceof IPipeTile<?, ?>pipeTile) { | ||
| if (pipeTile.isPainted() && getColorInt(world, pos, facing, player) == newColor) { | ||
| return false; | ||
| } else { | ||
| pipeTile.setPaintingColor(newColor); | ||
| return true; | ||
| } | ||
| } | ||
|
|
||
| return false; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean removeColor(@NotNull World world, @NotNull BlockPos pos, @NotNull EnumFacing facing, | ||
| @NotNull EntityPlayer player) { | ||
| if (world.getTileEntity(pos) instanceof IPipeTile<?, ?>pipeTile && pipeTile.isPainted()) { | ||
| pipeTile.setPaintingColor(-1); | ||
| return true; | ||
| } | ||
|
|
||
| return false; | ||
| } | ||
|
|
||
| @Override | ||
| public @Nullable EnumDyeColor getColor(@NotNull World world, @NotNull BlockPos pos, @NotNull EnumFacing facing, | ||
| @NotNull EntityPlayer player) { | ||
| return ColorUtil.getDyeColorFromRGB(getColorInt(world, pos, facing, player)); | ||
| } | ||
|
|
||
| @Override | ||
| public int getColorInt(@NotNull World world, @NotNull BlockPos pos, @NotNull EnumFacing facing, | ||
| @NotNull EntityPlayer player) { | ||
| if (world.getTileEntity(pos) instanceof IPipeTile<?, ?>pipeTile && pipeTile.isPainted()) { | ||
| return pipeTile.getPaintingColor(); | ||
| } | ||
|
|
||
| return -1; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean supportsARGB() { | ||
| return true; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean isValid(@NotNull World world, @NotNull BlockPos pos, @NotNull EnumFacing facing, | ||
| @NotNull EntityPlayer player) { | ||
| return world.getTileEntity(pos) instanceof IPipeTile<?, ?>; | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is named
supportsARGBbut the MC colors don't provideAat all. Should this just be renamed tosupportsRGB?