/
InspirationsTools.java
241 lines (210 loc) · 9.7 KB
/
InspirationsTools.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
package knightminer.inspirations.tools;
import com.google.common.eventbus.Subscribe;
import knightminer.inspirations.common.CommonProxy;
import knightminer.inspirations.common.Config;
import knightminer.inspirations.common.EntityIds;
import knightminer.inspirations.common.PulseBase;
import knightminer.inspirations.library.Util;
import knightminer.inspirations.shared.InspirationsShared;
import knightminer.inspirations.tools.client.BarometerGetter;
import knightminer.inspirations.tools.client.NorthCompassGetter;
import knightminer.inspirations.tools.client.PhotometerGetter;
import knightminer.inspirations.tools.enchantment.EnchantmentShieldFire;
import knightminer.inspirations.tools.enchantment.EnchantmentShieldKnockback;
import knightminer.inspirations.tools.enchantment.EnchantmentShieldProtection;
import knightminer.inspirations.tools.enchantment.EnchantmentShieldThorns;
import knightminer.inspirations.tools.entity.EntityModArrow;
import knightminer.inspirations.tools.item.ItemCrook;
import knightminer.inspirations.tools.item.ItemEnchantableShield;
import knightminer.inspirations.tools.item.ItemModArrow;
import knightminer.inspirations.tools.item.ItemRedstoneCharger;
import knightminer.inspirations.tools.item.ItemWaypointCompass;
import knightminer.inspirations.tools.recipe.WaypointCompassCopyRecipe;
import knightminer.inspirations.utility.block.BlockRedstoneCharge;
import net.minecraft.block.Block;
import net.minecraft.block.BlockDispenser;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.dispenser.BehaviorProjectileDispense;
import net.minecraft.dispenser.IBlockSource;
import net.minecraft.dispenser.IPosition;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.enchantment.EnchantmentProtection;
import net.minecraft.entity.IProjectile;
import net.minecraft.entity.projectile.EntityArrow;
import net.minecraft.init.Bootstrap;
import net.minecraft.init.Items;
import net.minecraft.inventory.EntityEquipmentSlot;
import net.minecraft.item.Item;
import net.minecraft.item.Item.ToolMaterial;
import net.minecraft.item.ItemArrow;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.util.EnumHelper;
import net.minecraftforge.event.RegistryEvent.Register;
import net.minecraftforge.fml.common.SidedProxy;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.registry.EntityEntry;
import net.minecraftforge.registries.IForgeRegistry;
import slimeknights.mantle.pulsar.pulse.Pulse;
@Pulse(id = InspirationsTools.pulseID, description = "Adds various tools or tweaks to vanilla tools")
public class InspirationsTools extends PulseBase {
public static final String pulseID = "InspirationsTools";
@SidedProxy(clientSide = "knightminer.inspirations.tools.ToolsClientProxy", serverSide = "knightminer.inspirations.common.CommonProxy")
public static CommonProxy proxy;
// items
public static Item redstoneCharger;
public static Item woodenCrook;
public static Item stoneCrook;
public static Item boneCrook;
public static Item blazeCrook;
public static Item witherCrook;
public static Item northCompass;
public static Item barometer;
public static Item photometer;
public static Item waypointCompass;
// tool materials
public static ToolMaterial bone;
public static ToolMaterial blaze;
public static ToolMaterial wither;
// blocks
public static Block redstoneCharge;
public static ItemArrow arrow;
@Subscribe
public void preInit(FMLPreInitializationEvent event) {
proxy.preInit();
if(Config.separateCrook) {
bone = EnumHelper.addToolMaterial(Util.prefix("bone"), 1, 225, 4.0F, 1.5F, 10);
if(Config.netherCrooks) {
blaze = EnumHelper.addToolMaterial(Util.prefix("blaze"), 2, 300, 6.0F, 2.0F, 20);
wither = EnumHelper.addToolMaterial(Util.prefix("wither"), 2, 375, 6.0F, 1.5F, 10);
}
}
}
@SubscribeEvent
public void registerBlocks(Register<Block> event) {
IForgeRegistry<Block> r = event.getRegistry();
if(Config.enableRedstoneCharge || Config.enableChargedArrow) {
redstoneCharge = registerBlock(r, new BlockRedstoneCharge(), "redstone_charge");
}
}
@SubscribeEvent
public void registerItems(Register<Item> event) {
IForgeRegistry<Item> r = event.getRegistry();
arrow = registerItem(r, new ItemModArrow(), "arrow");
if(Config.enableRedstoneCharge) {
redstoneCharger = registerItem(r, new ItemRedstoneCharger(), "redstone_charger");
}
if(Config.separateCrook) {
woodenCrook = registerItem(r, new ItemCrook(ToolMaterial.WOOD), "wooden_crook");
stoneCrook = registerItem(r, new ItemCrook(ToolMaterial.STONE), "stone_crook");
boneCrook = registerItem(r, new ItemCrook(bone), "bone_crook");
if(Config.netherCrooks) {
blazeCrook = registerItem(r, new ItemCrook(blaze), "blaze_crook");
witherCrook = registerItem(r, new ItemCrook(wither), "wither_crook");
}
}
if(Config.enableNorthCompass) {
northCompass = registerItem(r, new Item().setCreativeTab(CreativeTabs.TOOLS), "north_compass");
northCompass.addPropertyOverride(new ResourceLocation("angle"), new NorthCompassGetter());
if(Config.renameVanillaCompass) {
Items.COMPASS.setUnlocalizedName(Util.prefix("origin_compass"));
}
}
if(Config.enableBarometer) {
barometer = registerItem(r, new Item().setCreativeTab(CreativeTabs.TOOLS), "barometer");
barometer.addPropertyOverride(new ResourceLocation("height"), new BarometerGetter());
}
if(Config.enablePhotometer) {
photometer = registerItem(r, new Item().setCreativeTab(CreativeTabs.TOOLS), "photometer");
photometer.addPropertyOverride(new ResourceLocation("light"), new PhotometerGetter());
}
if(Config.enableWaypointCompass) {
waypointCompass = registerItem(r, new ItemWaypointCompass(), "waypoint_compass");
}
if(Config.shieldEnchantmentTable) {
register(r, new ItemEnchantableShield(), new ResourceLocation("shield"));
}
}
@SubscribeEvent
public void registerEntities(Register<EntityEntry> event) {
IForgeRegistry<EntityEntry> r = event.getRegistry();
r.register(getEntityBuilder(EntityModArrow.class, "arrow", EntityIds.ARROW)
.tracker(64, 1, false)
.build());
}
@SubscribeEvent
public void registerRecipes(Register<IRecipe> event) {
IForgeRegistry<IRecipe> r = event.getRegistry();
if(Config.copyWaypointCompass) {
register(r, new WaypointCompassCopyRecipe(), "waypoint_compass_copy");
}
}
@SubscribeEvent
public void registerEnchantments(Register<Enchantment> event) {
IForgeRegistry<Enchantment> r = event.getRegistry();
if(Config.moreShieldEnchantments) {
EntityEquipmentSlot[] slots = new EntityEquipmentSlot[] {EntityEquipmentSlot.HEAD, EntityEquipmentSlot.CHEST, EntityEquipmentSlot.LEGS, EntityEquipmentSlot.FEET};
register(r, new EnchantmentShieldProtection(Enchantment.Rarity.COMMON, EnchantmentProtection.Type.ALL, slots), new ResourceLocation("protection"));
register(r, new EnchantmentShieldProtection(Enchantment.Rarity.UNCOMMON, EnchantmentProtection.Type.FIRE, slots), new ResourceLocation("fire_protection"));
register(r, new EnchantmentShieldProtection(Enchantment.Rarity.UNCOMMON, EnchantmentProtection.Type.PROJECTILE, slots), new ResourceLocation("projectile_protection"));
register(r, new EnchantmentShieldProtection(Enchantment.Rarity.RARE, EnchantmentProtection.Type.EXPLOSION, slots), new ResourceLocation("blast_protection"));
register(r, new EnchantmentShieldThorns(Enchantment.Rarity.VERY_RARE, slots), new ResourceLocation("thorns"));
slots = new EntityEquipmentSlot[] {EntityEquipmentSlot.MAINHAND};
register(r, new EnchantmentShieldKnockback(Enchantment.Rarity.UNCOMMON, slots), new ResourceLocation("knockback"));
register(r, new EnchantmentShieldFire(Enchantment.Rarity.RARE, slots), new ResourceLocation("fire_aspect"));
}
}
@Subscribe
public void init(FMLInitializationEvent event) {
proxy.init();
if(Config.separateCrook) {
bone.setRepairItem(new ItemStack(Items.BONE));
if(Config.netherCrooks) {
blaze.setRepairItem(new ItemStack(Items.BLAZE_ROD));
wither.setRepairItem(InspirationsShared.witherBone);
}
}
registerDispenserBehavior();
}
@Subscribe
public void postInit(FMLPostInitializationEvent event) {
proxy.postInit();
MinecraftForge.EVENT_BUS.register(ToolsEvents.class);
}
private void registerDispenserBehavior() {
registerDispenserBehavior(arrow, new BehaviorProjectileDispense() {
@Override
protected IProjectile getProjectileEntity(World world, IPosition position, ItemStack stack) {
EntityModArrow arrow = new EntityModArrow(world, position.getX(), position.getY(), position.getZ(), stack.getMetadata());
arrow.pickupStatus = EntityArrow.PickupStatus.ALLOWED;
return arrow;
}
});
registerDispenserBehavior(redstoneCharger, new Bootstrap.BehaviorDispenseOptional() {
@Override
protected ItemStack dispenseStack(IBlockSource source, ItemStack stack) {
this.successful = true;
World world = source.getWorld();
EnumFacing facing = source.getBlockState().getValue(BlockDispenser.FACING);
BlockPos pos = source.getBlockPos().offset(facing);
if (redstoneCharge.canPlaceBlockAt(world, pos)) {
world.setBlockState(pos, redstoneCharge.getDefaultState().withProperty(BlockRedstoneCharge.FACING, facing));
if (stack.attemptDamageItem(1, world.rand, null)) {
stack.setCount(0);
}
} else {
this.successful = false;
}
return stack;
}
});
}
}