Skip to content

Commit b493fbf

Browse files
committed
WIP stuff
1 parent 6cfb27c commit b493fbf

10 files changed

Lines changed: 62 additions & 23 deletions

src/main/java/gregtech/api/color/ColoredBlockContainer.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import gregtech.api.color.containers.VanillaColorContainer;
99
import gregtech.api.util.GTUtility;
1010
import gregtech.api.util.Mods;
11+
import gregtech.common.items.behaviors.spray.AbstractSprayBehavior;
1112

1213
import net.minecraft.entity.player.EntityPlayer;
1314
import net.minecraft.item.EnumDyeColor;
@@ -109,7 +110,5 @@ public boolean colorMatches(@NotNull World world, @NotNull BlockPos pos, @NotNul
109110
return getColorInt(world, pos, facing, player) == color;
110111
}
111112

112-
public boolean supportsARGB() {
113-
return false;
114-
}
113+
public abstract boolean supportsMode(@NotNull AbstractSprayBehavior.ColorMode colorMode);
115114
}

src/main/java/gregtech/api/color/containers/AE2ColorContainer.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package gregtech.api.color.containers;
22

33
import gregtech.api.color.ColoredBlockContainer;
4+
import gregtech.common.items.behaviors.spray.AbstractSprayBehavior;
45

56
import net.minecraft.entity.player.EntityPlayer;
67
import net.minecraft.item.EnumDyeColor;
@@ -71,4 +72,9 @@ public boolean isBlockValid(@NotNull World world, @NotNull BlockPos pos, @NotNul
7172
@NotNull EntityPlayer player) {
7273
return world.getTileEntity(pos) instanceof IColorableTile;
7374
}
75+
76+
@Override
77+
public boolean supportsMode(AbstractSprayBehavior.@NotNull ColorMode colorMode) {
78+
return colorMode == AbstractSprayBehavior.ColorMode.DYE_ONLY;
79+
}
7480
}

src/main/java/gregtech/api/color/containers/BedColorContainer.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package gregtech.api.color.containers;
22

33
import gregtech.api.color.ColoredBlockContainer;
4+
import gregtech.common.items.behaviors.spray.AbstractSprayBehavior;
45

56
import net.minecraft.block.BlockBed;
67
import net.minecraft.block.BlockHorizontal;
@@ -67,4 +68,9 @@ public boolean isBlockValid(@NotNull World world, @NotNull BlockPos pos, @NotNul
6768
@NotNull EntityPlayer player) {
6869
return world.getTileEntity(pos) instanceof TileEntityBed;
6970
}
71+
72+
@Override
73+
public boolean supportsMode(AbstractSprayBehavior.@NotNull ColorMode colorMode) {
74+
return colorMode == AbstractSprayBehavior.ColorMode.DYE_ONLY;
75+
}
7076
}

src/main/java/gregtech/api/color/containers/GTPipeColorContainer.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import gregtech.api.color.ColoredBlockContainer;
44
import gregtech.api.pipenet.tile.IPipeTile;
55
import gregtech.api.util.ColorUtil;
6+
import gregtech.common.items.behaviors.spray.AbstractSprayBehavior;
67

78
import net.minecraft.entity.player.EntityPlayer;
89
import net.minecraft.item.EnumDyeColor;
@@ -85,14 +86,14 @@ public int getColorInt(@NotNull World world, @NotNull BlockPos pos, @NotNull Enu
8586
return -1;
8687
}
8788

88-
@Override
89-
public boolean supportsARGB() {
90-
return true;
91-
}
92-
9389
@Override
9490
public boolean isBlockValid(@NotNull World world, @NotNull BlockPos pos, @NotNull EnumFacing facing,
9591
@NotNull EntityPlayer player) {
9692
return world.getTileEntity(pos) instanceof IPipeTile<?, ?>;
9793
}
94+
95+
@Override
96+
public boolean supportsMode(AbstractSprayBehavior.@NotNull ColorMode colorMode) {
97+
return true;
98+
}
9899
}

src/main/java/gregtech/api/color/containers/MTEColorContainer.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import gregtech.api.color.ColoredBlockContainer;
44
import gregtech.api.metatileentity.MetaTileEntity;
55
import gregtech.api.util.ColorUtil;
6+
import gregtech.common.items.behaviors.spray.AbstractSprayBehavior;
67

78
import net.minecraft.entity.player.EntityPlayer;
89
import net.minecraft.item.EnumDyeColor;
@@ -99,7 +100,7 @@ public boolean isBlockValid(@NotNull World world, @NotNull BlockPos pos, @NotNul
99100
}
100101

101102
@Override
102-
public boolean supportsARGB() {
103+
public boolean supportsMode(AbstractSprayBehavior.@NotNull ColorMode colorMode) {
103104
return true;
104105
}
105106
}

src/main/java/gregtech/api/color/containers/NullColorContainer.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import gregtech.api.color.ColoredBlockContainer;
44
import gregtech.api.util.GTUtility;
5+
import gregtech.common.items.behaviors.spray.AbstractSprayBehavior;
56

67
import net.minecraft.entity.player.EntityPlayer;
78
import net.minecraft.item.EnumDyeColor;
@@ -49,4 +50,9 @@ public boolean colorMatches(@NotNull World world, @NotNull BlockPos pos, @NotNul
4950
@NotNull EntityPlayer player, @Nullable EnumDyeColor color) {
5051
return false;
5152
}
53+
54+
@Override
55+
public boolean supportsMode(AbstractSprayBehavior.@NotNull ColorMode colorMode) {
56+
return false;
57+
}
5258
}

src/main/java/gregtech/api/color/containers/VanillaColorContainer.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package gregtech.api.color.containers;
22

33
import gregtech.api.color.ColoredBlockContainer;
4+
import gregtech.common.items.behaviors.spray.AbstractSprayBehavior;
45

56
import net.minecraft.block.Block;
67
import net.minecraft.block.BlockColored;
@@ -130,4 +131,9 @@ public boolean isBlockValid(@NotNull World world, @NotNull BlockPos pos, @NotNul
130131

131132
return false;
132133
}
134+
135+
@Override
136+
public boolean supportsMode(AbstractSprayBehavior.@NotNull ColorMode colorMode) {
137+
return colorMode == AbstractSprayBehavior.ColorMode.DYE_ONLY;
138+
}
133139
}

src/main/java/gregtech/common/items/behaviors/spray/AbstractSprayBehavior.java

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
import net.minecraft.entity.player.EntityPlayer;
1313
import net.minecraft.item.EnumDyeColor;
14+
import net.minecraft.item.Item;
1415
import net.minecraft.item.ItemStack;
1516
import net.minecraft.util.EnumActionResult;
1617
import net.minecraft.util.EnumFacing;
@@ -82,7 +83,7 @@ public static boolean isSprayCan(@NotNull ItemStack stack) {
8283

8384
/**
8485
* Call from your items
85-
* {@link net.minecraft.item.Item#onItemUseFirst(EntityPlayer, World, BlockPos, EnumFacing, float, float, float, EnumHand)}
86+
* {@link Item#onItemUseFirst(EntityPlayer, World, BlockPos, EnumFacing, float, float, float, EnumHand)}
8687
* or the meta item equivalent to check if block is sprayable early enough in the click handling chain.
8788
*/
8889
@SuppressWarnings("UnusedReturnValue")
@@ -94,7 +95,7 @@ public static boolean isSprayCan(@NotNull ItemStack stack) {
9495

9596
/**
9697
* Call from your items
97-
* {@link net.minecraft.item.Item#onItemUseFirst(EntityPlayer, World, BlockPos, EnumFacing, float, float, float, EnumHand)}
98+
* {@link Item#onItemUseFirst(EntityPlayer, World, BlockPos, EnumFacing, float, float, float, EnumHand)}
9899
* or the meta item equivalent to check if block is sprayable early enough in the click handling chain.
99100
*/
100101
public static @NotNull EnumActionResult handleExternalSpray(@NotNull EntityPlayer player,
@@ -138,6 +139,7 @@ public EnumActionResult onItemUseFirst(EntityPlayer player, World world, BlockPo
138139
int color = getColorInt(sprayCan);
139140
if (hitSide != null && firstPipe != null && firstPipe.isConnected(hitSide) &&
140141
(firstPipe.isPainted() ? firstPipe.getPaintingColor() != color : color != -1)) {
142+
if (world.isRemote) return EnumActionResult.SUCCESS;
141143
traversePipes(firstPipe, hitSide, player, sprayCan, color);
142144
return EnumActionResult.SUCCESS;
143145
}
@@ -146,15 +148,11 @@ public EnumActionResult onItemUseFirst(EntityPlayer player, World world, BlockPo
146148
}
147149

148150
ColoredBlockContainer colorContainer = ColoredBlockContainer.getContainer(world, pos, facing, player);
149-
if (colorContainer.supportsARGB() ? colorContainer.setColor(world, pos, facing, player, getColorInt(sprayCan)) :
150-
colorContainer.setColor(world, pos, facing, player, getColor(sprayCan))) {
151-
onSpray(player, sprayCan);
152-
return EnumActionResult.SUCCESS;
153-
}
154-
155-
return EnumActionResult.PASS;
151+
//TODO: reimplement spraying according to the mode of the spray can
156152
}
157153

154+
public abstract @NotNull AbstractSprayBehavior.ColorMode getColorMode(@NotNull ItemStack sprayCan);
155+
158156
protected void traversePipes(@NotNull IPipeTile<?, ?> pipeTile, @NotNull EnumFacing facing,
159157
@NotNull EntityPlayer player, @NotNull ItemStack sprayCan, int color) {
160158
if (canPipeBePainted(pipeTile, color) && pipeTile.getNeighbor(facing) instanceof IPipeTile<?, ?>nextPipe) {
@@ -195,4 +193,10 @@ protected void traversePipes(@NotNull IPipeTile<?, ?> pipeTile, @NotNull EnumFac
195193
private static boolean canPipeBePainted(@NotNull IPipeTile<?, ?> pipeTile, int color) {
196194
return pipeTile.isPainted() ? pipeTile.getPaintingColor() != color : color != -1;
197195
}
196+
197+
public enum ColorMode {
198+
DYE_ONLY,
199+
ARGB_ONLY,
200+
EITHER
201+
}
198202
}

src/main/java/gregtech/common/items/behaviors/spray/CreativeSprayBehavior.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -202,24 +202,29 @@ public int getColorInt(@NotNull ItemStack sprayCan) {
202202
return tag.getBoolean(NBT_KEY_USES_RGB) ? tag.getInteger(NBT_KEY_RGB_COLOR) : super.getColorInt(sprayCan);
203203
}
204204

205-
public static void setColor(@NotNull ItemStack sprayCan, @Nullable EnumDyeColor color) {
205+
@Override
206+
public @NotNull ColorMode getColorMode(@NotNull ItemStack sprayCan) {
207+
return usesRGB(sprayCan) ? ColorMode.ARGB_ONLY : ColorMode.DYE_ONLY;
208+
}
209+
210+
public void setColor(@NotNull ItemStack sprayCan, @Nullable EnumDyeColor color) {
206211
GTUtility.getOrCreateNbtCompound(sprayCan).setInteger(NBT_KEY_COLOR, color == null ? -1 : color.ordinal());
207212
}
208213

209-
public static void setColorOrdinal(@NotNull ItemStack sprayCan, int ordinal) {
214+
public void setColorOrdinal(@NotNull ItemStack sprayCan, int ordinal) {
210215
GTUtility.getOrCreateNbtCompound(sprayCan).setInteger(NBT_KEY_COLOR,
211216
ordinal >= 0 && ordinal <= 15 ? ordinal : -1);
212217
}
213218

214-
public static void setColor(@NotNull ItemStack sprayCan, int argbColor) {
219+
public void setColor(@NotNull ItemStack sprayCan, int argbColor) {
215220
GTUtility.getOrCreateNbtCompound(sprayCan).setInteger(NBT_KEY_RGB_COLOR, argbColor);
216221
}
217222

218-
public static boolean usesRGB(@NotNull ItemStack sprayCan) {
223+
public boolean usesRGB(@NotNull ItemStack sprayCan) {
219224
return GTUtility.getOrCreateNbtCompound(sprayCan).getBoolean(NBT_KEY_USES_RGB);
220225
}
221226

222-
public static void useRGB(@NotNull ItemStack sprayCan, boolean bool) {
227+
public void useRGB(@NotNull ItemStack sprayCan, boolean bool) {
223228
GTUtility.getOrCreateNbtCompound(sprayCan).setBoolean(NBT_KEY_USES_RGB, bool);
224229
}
225230

src/main/java/gregtech/common/items/behaviors/spray/DurabilitySprayBehavior.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,11 @@ protected boolean damageCan(@NotNull ItemStack sprayCan) {
7777
return this.color;
7878
}
7979

80+
@Override
81+
public @NotNull ColorMode getColorMode(@NotNull ItemStack sprayCan) {
82+
return ColorMode.DYE_ONLY;
83+
}
84+
8085
protected int getUsesLeft(@NotNull ItemStack stack) {
8186
if (stack.isItemEqual(replacementStack)) return 0;
8287

0 commit comments

Comments
 (0)