Browse Source

Axes Saws and Chainsaws can now place saplings

Gregorius Techneticies 2 months ago
parent
commit
fe3b4e562e
Signed by: Gregorius Techneticies <gregoriustech@gmail.com> GPG Key ID: 1B693EA14F2FD70F

+ 1
- 0
CHANGELOG.md View File

@@ -12,6 +12,7 @@ Nothing (I tend to only add finished Stuff to the Changelog).
12 12
 6.14.09: (Not released yet, happens whenever a Bugfix needs to be released, Bear is still testing GT6, while I'm working on my Game)
13 13
 [COMPAT] Aroma1997's Mining Dimension is now Compatible with my Worldgen.
14 14
 [FIXED] Chainsaws used WAY too much durability for Treecapitation!
15
+[ADDED] Axes, Saws and Chainsaws can now place Saplings too. They will still place Workbenches if Saplings cant be placed.
15 16
 [ADDED] Tooltip for Covers that can be controlled with the Cover Controller Cover. In case of Covers where the Cover Controller Cover is required (such as Shutter Cover), it will be Cyan instead of Dark Gray to make it easier to see.
16 17
 
17 18
 

+ 60
- 0
src/main/java/gregapi/item/multiitem/behaviors/Behavior_Place_Sapling.java View File

@@ -0,0 +1,60 @@
1
+/**
2
+ * Copyright (c) 2021 GregTech-6 Team
3
+ *
4
+ * This file is part of GregTech.
5
+ *
6
+ * GregTech is free software: you can redistribute it and/or modify
7
+ * it under the terms of the GNU Lesser General Public License as published by
8
+ * the Free Software Foundation, either version 3 of the License, or
9
+ * (at your option) any later version.
10
+ *
11
+ * GregTech is distributed in the hope that it will be useful,
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ * GNU Lesser General Public License for more details.
15
+ *
16
+ * You should have received a copy of the GNU Lesser General Public License
17
+ * along with GregTech. If not, see <http://www.gnu.org/licenses/>.
18
+ */
19
+
20
+package gregapi.item.multiitem.behaviors;
21
+
22
+import static gregapi.data.CS.*;
23
+
24
+import gregapi.data.OP;
25
+import gregapi.item.multiitem.MultiItem;
26
+import gregapi.item.multiitem.behaviors.IBehavior.AbstractBehaviorDefault;
27
+import gregapi.util.ST;
28
+import gregapi.util.UT;
29
+import net.minecraft.entity.player.EntityPlayer;
30
+import net.minecraft.item.ItemStack;
31
+import net.minecraft.world.World;
32
+
33
+public class Behavior_Place_Sapling extends AbstractBehaviorDefault {
34
+	public static final Behavior_Place_Sapling INSTANCE = new Behavior_Place_Sapling();
35
+	
36
+	@Override
37
+	public boolean onItemUse(MultiItem aItem, ItemStack aStack, EntityPlayer aPlayer, World aWorld, int aX, int aY, int aZ, byte aSide, float aHitX, float aHitY, float aHitZ) {
38
+		if (aWorld.isRemote || aPlayer == null || !aPlayer.canPlayerEdit(aX, aY, aZ, aSide, aStack)) return F;
39
+		
40
+		// Scan Inventory for suitable Saplings.
41
+		for (int i = 0; i < aPlayer.inventory.mainInventory.length; i++) {
42
+			int tIndex = aPlayer.inventory.mainInventory.length-i-1;
43
+			ItemStack tStack = aPlayer.inventory.mainInventory[tIndex];
44
+			// Any OreDict Saplings.
45
+			if (!OP.treeSapling.contains(tStack)) continue;
46
+			
47
+			int tOldSize = tStack.stackSize;
48
+			if (tStack.tryPlaceItemIntoWorld(aPlayer, aWorld, aX, aY, aZ, aSide, aHitX, aHitY, aHitZ)) {
49
+				if (UT.Entities.hasInfiniteItems(aPlayer)) {
50
+					tStack.stackSize = tOldSize;
51
+				} else {
52
+					ST.use(aPlayer, tIndex, tStack, 0);
53
+				}
54
+				return T;
55
+			}
56
+			return F;
57
+		}
58
+		return F;
59
+	}
60
+}

+ 2
- 2
src/main/java/gregapi/oredict/OreDictPrefix.java View File

@@ -1,5 +1,5 @@
1 1
 /**
2
- * Copyright (c) 2020 GregTech-6 Team
2
+ * Copyright (c) 2021 GregTech-6 Team
3 3
  *
4 4
  * This file is part of GregTech.
5 5
  *
@@ -496,7 +496,7 @@ public final class OreDictPrefix implements IOreDictListenerEvent, ITagDataConta
496 496
 	/** This is used to determine if any of the ItemStacks belongs to this Prefix. */
497 497
 	public boolean contains(ItemStack... aStacks) {
498 498
 		if (aStacks == null) return F;
499
-		for (ItemStack aStack : aStacks) if (mRegisteredItems.contains(aStack, T)) return T;
499
+		for (ItemStack aStack : aStacks) if (ST.valid(aStack) && mRegisteredItems.contains(aStack, T)) return T;
500 500
 		return F;
501 501
 	}
502 502
 	

+ 2
- 0
src/main/java/gregtech/items/tools/early/GT_Tool_Axe.java View File

@@ -29,6 +29,7 @@ import gregapi.data.MD;
29 29
 import gregapi.data.MT;
30 30
 import gregapi.data.OP;
31 31
 import gregapi.item.multiitem.MultiItemTool;
32
+import gregapi.item.multiitem.behaviors.Behavior_Place_Sapling;
32 33
 import gregapi.item.multiitem.behaviors.Behavior_Place_Workbench;
33 34
 import gregapi.item.multiitem.behaviors.Behavior_Tool;
34 35
 import gregapi.item.multiitem.tools.ToolStats;
@@ -152,6 +153,7 @@ public class GT_Tool_Axe extends ToolStats {
152 153
 	@Override
153 154
 	public void onStatsAddedToTool(MultiItemTool aItem, int aID) {
154 155
 		aItem.addItemBehavior(aID, new Behavior_Tool(TOOL_axe, SFX.MC_DIG_WOOD, getToolDamagePerContainerCraft(), F, T));
156
+		aItem.addItemBehavior(aID, Behavior_Place_Sapling.INSTANCE);
155 157
 		aItem.addItemBehavior(aID, Behavior_Place_Workbench.INSTANCE);
156 158
 	}
157 159
 	

+ 3
- 1
src/main/java/gregtech/items/tools/early/GT_Tool_Saw.java View File

@@ -1,5 +1,5 @@
1 1
 /**
2
- * Copyright (c) 2020 GregTech-6 Team
2
+ * Copyright (c) 2021 GregTech-6 Team
3 3
  *
4 4
  * This file is part of GregTech.
5 5
  *
@@ -30,6 +30,7 @@ import gregapi.data.IL;
30 30
 import gregapi.data.MT;
31 31
 import gregapi.data.OP;
32 32
 import gregapi.item.multiitem.MultiItemTool;
33
+import gregapi.item.multiitem.behaviors.Behavior_Place_Sapling;
33 34
 import gregapi.item.multiitem.behaviors.Behavior_Place_Workbench;
34 35
 import gregapi.item.multiitem.behaviors.Behavior_Tool;
35 36
 import gregapi.item.multiitem.tools.ToolStats;
@@ -187,6 +188,7 @@ public class GT_Tool_Saw extends ToolStats {
187 188
 	@Override
188 189
 	public void onStatsAddedToTool(MultiItemTool aItem, int aID) {
189 190
 		aItem.addItemBehavior(aID, new Behavior_Tool(TOOL_saw, SFX.MC_DIG_WOOD, getToolDamagePerContainerCraft(), F, T));
191
+		aItem.addItemBehavior(aID, Behavior_Place_Sapling.INSTANCE);
190 192
 		aItem.addItemBehavior(aID, Behavior_Place_Workbench.INSTANCE);
191 193
 	}
192 194
 	

+ 2
- 0
src/main/java/gregtech/items/tools/electric/GT_Tool_Chainsaw_LV.java View File

@@ -29,6 +29,7 @@ import gregapi.data.MD;
29 29
 import gregapi.data.MT;
30 30
 import gregapi.data.OP;
31 31
 import gregapi.item.multiitem.MultiItemTool;
32
+import gregapi.item.multiitem.behaviors.Behavior_Place_Sapling;
32 33
 import gregapi.item.multiitem.behaviors.Behavior_Place_Workbench;
33 34
 import gregapi.item.multiitem.behaviors.Behavior_Tool;
34 35
 import gregapi.old.Textures;
@@ -141,6 +142,7 @@ public class GT_Tool_Chainsaw_LV extends GT_Tool_Axe {
141 142
 	@Override
142 143
 	public void onStatsAddedToTool(MultiItemTool aItem, int aID) {
143 144
 		aItem.addItemBehavior(aID, new Behavior_Tool(TOOL_saw, SFX.MC_DIG_WOOD, getToolDamagePerContainerCraft(), F, T));
145
+		aItem.addItemBehavior(aID, Behavior_Place_Sapling.INSTANCE);
144 146
 		aItem.addItemBehavior(aID, Behavior_Place_Workbench.INSTANCE);
145 147
 	}
146 148
 	

Loading…
Cancel
Save