Skip to content

Commit 138a0df

Browse files
committed
-arrows
1 parent d00df90 commit 138a0df

File tree

17 files changed

+355
-13
lines changed

17 files changed

+355
-13
lines changed

common/src/main/java/smartin/miapi/craft/CraftAction.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import smartin.miapi.blocks.ModularWorkBenchEntity;
1414
import smartin.miapi.item.ModularItemStackConverter;
1515
import smartin.miapi.modules.ItemModule;
16-
import smartin.miapi.modules.cache.ModularItemCache;
1716
import smartin.miapi.modules.properties.SlotProperty;
1817
import smartin.miapi.modules.properties.util.CraftingProperty;
1918
import smartin.miapi.network.Networking;
@@ -229,7 +228,6 @@ private ItemStack craft() {
229228
return old;
230229
}
231230
//remove CacheKey so new cache gets Generated
232-
ModularItemCache.clearUUIDFor(craftingStack);
233231
ItemModule.ModuleInstance oldBaseModule = ItemModule.getModules(old);
234232
ItemModule.ModuleInstance newBaseModule = ItemModule.ModuleInstance.fromString(oldBaseModule.toString());
235233
Map<Integer, ItemModule.ModuleInstance> subModuleMap = new HashMap<>();
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package smartin.miapi.item.modular.items;
2+
3+
import net.minecraft.entity.LivingEntity;
4+
import net.minecraft.entity.projectile.PersistentProjectileEntity;
5+
import net.minecraft.item.ArrowItem;
6+
import net.minecraft.item.Item;
7+
import net.minecraft.item.ItemStack;
8+
import net.minecraft.world.World;
9+
import smartin.miapi.item.modular.ModularItem;
10+
import smartin.miapi.modules.abilities.util.ItemProjectile.ItemProjectile;
11+
12+
public class ModularArrow extends ArrowItem implements ModularItem {
13+
public ModularArrow() {
14+
super(new Item.Settings().maxCount(64));
15+
//ItemTags.ARROWS
16+
}
17+
18+
public PersistentProjectileEntity createArrow(World world, ItemStack stack, LivingEntity shooter) {
19+
stack = stack.copy();
20+
stack.setCount(1);
21+
return new ItemProjectile(world, shooter, stack);
22+
}
23+
}

common/src/main/java/smartin/miapi/modules/abilities/util/ItemProjectile/ItemProjectile.java

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package smartin.miapi.modules.abilities.util.ItemProjectile;
22

33
import dev.architectury.event.EventResult;
4+
import net.minecraft.block.BlockState;
45
import net.minecraft.enchantment.EnchantmentHelper;
56
import net.minecraft.entity.Entity;
67
import net.minecraft.entity.EntityType;
@@ -16,6 +17,7 @@
1617
import net.minecraft.server.network.ServerPlayerEntity;
1718
import net.minecraft.sound.SoundEvent;
1819
import net.minecraft.sound.SoundEvents;
20+
import net.minecraft.util.hit.BlockHitResult;
1921
import net.minecraft.util.hit.EntityHitResult;
2022
import net.minecraft.util.math.Vec3d;
2123
import net.minecraft.world.World;
@@ -42,6 +44,7 @@ public class ItemProjectile extends PersistentProjectileEntity {
4244
public WrappedSoundEvent hitEntitySound = new WrappedSoundEvent(this.getHitSound(), 1.0f, 1.0f);
4345
public WrappedSoundEvent hitGroundSound = new WrappedSoundEvent(this.getHitSound(), 1.0f, 1.0f);
4446
public ProjectileHitBehaviour projectileHitBehaviour = new EntityBounceBehaviour();
47+
private BlockState inBlockState;
4548

4649
public ItemProjectile(EntityType<? extends Entity> entityType, World world) {
4750
super((EntityType<? extends PersistentProjectileEntity>) entityType, world);
@@ -74,9 +77,9 @@ public ItemStack getBowItem() {
7477
@Override
7578
protected void initDataTracker() {
7679
super.initDataTracker();
77-
this.dataTracker.startTracking(THROWING_STACK, ItemStack.EMPTY);
7880
this.dataTracker.startTracking(LOYALTY, (byte) 0);
7981
this.dataTracker.startTracking(ENCHANTED, false);
82+
this.dataTracker.startTracking(THROWING_STACK, ItemStack.EMPTY);
8083
this.dataTracker.startTracking(BOW_ITEM_STACK, ItemStack.EMPTY);
8184
this.dataTracker.startTracking(WATER_DRAG, 0.99f);
8285
this.dataTracker.startTracking(SPEED_DAMAGE, true);
@@ -94,6 +97,7 @@ public void setSpeedDamage(boolean speedDamage) {
9497
@Override
9598
public void tick() {
9699
if (this.inGroundTime > 4) {
100+
this.setVelocity(new Vec3d(0, 0, 0));
97101
this.dealtDamage = true;
98102
}
99103

@@ -109,12 +113,12 @@ public void tick() {
109113
} else {
110114
this.setNoClip(true);
111115
Vec3d targetDir = entity.getEyePos().subtract(this.getPos());
112-
this.setPos(this.getX(), this.getY() + targetDir.y * 0.015 * (double) loyaltyLevel, this.getZ());
116+
this.setPos(this.getX(), this.getY() + targetDir.y * 0.015 * loyaltyLevel, this.getZ());
113117
if (this.getWorld().isClient) {
114118
this.lastRenderY = this.getY();
115119
}
116120

117-
double speedAdjustment = 0.05 * (double) loyaltyLevel;
121+
double speedAdjustment = 0.05 * loyaltyLevel;
118122
this.setVelocity(this.getVelocity().multiply(0.95).add(targetDir.normalize().multiply(speedAdjustment)));
119123
if (this.returnTimer == 0) {
120124
this.playSound(SoundEvents.ITEM_TRIDENT_RETURN, 10.0F, 1.0F);
@@ -195,6 +199,11 @@ protected void onEntityHit(EntityHitResult entityHitResult) {
195199
this.playSound(this.hitEntitySound.event(), this.hitEntitySound.volume(), this.hitEntitySound.pitch());
196200
}
197201

202+
@Override
203+
protected void onBlockHit(BlockHitResult blockHitResult) {
204+
super.onBlockHit(blockHitResult);
205+
}
206+
198207
public float getProjectileDamage() {
199208
float damage = (float) getDamage();
200209
if (this.getSpeedDamage()) {
@@ -215,22 +224,22 @@ protected boolean tryPickup(PlayerEntity player) {
215224
case DISALLOWED:
216225
yield false;
217226
case ALLOWED: {
218-
yield tryInsertAtSlot(player.getInventory(),this.asItemStack(),slotId);
227+
yield tryInsertAtSlot(player.getInventory(), this.asItemStack(), slotId);
219228
}
220229
case CREATIVE_ONLY: {
221230
yield player.getAbilities().creativeMode;
222231
}
223232
};
224-
return earlyPickup || super.tryPickup(player) || this.isNoClip() && this.isOwner(player) && (tryInsertAtSlot(player.getInventory(),this.asItemStack(),slotId) || player.getInventory().insertStack(this.asItemStack()));
233+
return earlyPickup || super.tryPickup(player) || this.isNoClip() && this.isOwner(player) && (tryInsertAtSlot(player.getInventory(), this.asItemStack(), slotId) || player.getInventory().insertStack(this.asItemStack()));
225234
}
226235

227-
public boolean tryInsertAtSlot(PlayerInventory inventory,ItemStack stack,int slot){
228-
if(inventory.size()>slot && slot>0) {
236+
public boolean tryInsertAtSlot(PlayerInventory inventory, ItemStack stack, int slot) {
237+
if (inventory.size() > slot && slot > 0) {
229238
ItemStack inventoryStack = inventory.getStack(slot);
230-
if(inventoryStack.isEmpty()){
239+
if (inventoryStack.isEmpty()) {
231240
return inventory.insertStack(slot, stack);
232241
}
233-
if(ItemStack.canCombine(inventoryStack,stack)){
242+
if (ItemStack.canCombine(inventoryStack, stack)) {
234243
return inventory.insertStack(slot, stack);
235244
}
236245
}
@@ -265,6 +274,15 @@ public void readCustomDataFromNbt(NbtCompound nbt) {
265274
ItemStack bowItem = ItemStack.fromNbt(nbt.getCompound("BowItem"));
266275
this.dataTracker.set(BOW_ITEM_STACK, bowItem);
267276
}
277+
if(nbt.contains("WaterDrag")){
278+
this.dataTracker.set(WATER_DRAG,nbt.getFloat("WaterDrag"));
279+
}
280+
if(nbt.contains("SpeedDamage")){
281+
this.dataTracker.set(SPEED_DAMAGE,nbt.getBoolean("SpeedDamage"));
282+
}
283+
if(nbt.contains("PreferredSlot")){
284+
this.dataTracker.set(PREFERRED_SLOT,nbt.getInt("PreferredSlot"));
285+
}
268286

269287
this.dealtDamage = nbt.getBoolean("DealtDamage");
270288
this.dataTracker.set(LOYALTY, (byte) EnchantmentHelper.getLoyalty(this.thrownStack));
@@ -276,6 +294,9 @@ public void writeCustomDataToNbt(NbtCompound nbt) {
276294
nbt.put("ThrownItem", this.thrownStack.writeNbt(new NbtCompound()));
277295
nbt.put("BowItem", this.getBowItem().writeNbt(new NbtCompound()));
278296
nbt.putBoolean("DealtDamage", this.dealtDamage);
297+
nbt.putFloat("WaterDrag",this.dataTracker.get(WATER_DRAG));
298+
nbt.putBoolean("SpeedDamage",this.dataTracker.get(SPEED_DAMAGE));
299+
nbt.putInt("PreferredSlot", this.dataTracker.get(PREFERRED_SLOT));
279300
}
280301

281302
@Override

common/src/main/java/smartin/miapi/modules/properties/ItemIdProperty.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ public ItemStack preview(ItemStack old, ItemStack crafting, PlayerEntity player,
6262
if (item != null) {
6363
ItemStack newStack = new ItemStack(item);
6464
newStack.setNbt(crafting.getNbt());
65+
newStack.setCount(crafting.getCount());
6566
root.writeToItem(newStack);
6667
return newStack;
6768
}

common/src/main/java/smartin/miapi/modules/properties/material/AllowedMaterial.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public boolean canPerform(ItemStack old, ItemStack crafting, ModularWorkBenchEnt
6666
boolean isAllowed = (json.allowedMaterials.stream().anyMatch(allowedMaterial ->
6767
material.getGroups().contains(allowedMaterial)));
6868
if (isAllowed) {
69-
return input.getCount() * material.getValueOfItem(input) >= json.cost;
69+
return input.getCount() * material.getValueOfItem(input) >= json.cost * crafting.getCount();
7070
}
7171
}
7272
}

common/src/main/java/smartin/miapi/registries/RegistryInventory.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ public static void setup() {
243243
register(modularItems, "modular_mattock", ModularWeapon::new);
244244

245245
register(modularItems, "modular_bow", ExampleModularBowItem::new);
246+
register(modularItems, "modular_arrow", ModularArrow::new);
246247

247248
register(modularItems, "modular_helmet", ModularHelmet::new);
248249
register(modularItems, "modular_chestplate", ModularChestPlate::new);
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"parent": "item/generated",
3+
"textures": {
4+
"layer0": "miapi:item/arrow/head/default"
5+
}
6+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"parent": "item/generated",
3+
"textures": {
4+
"layer0": "miapi:item/arrow/shaft/default"
5+
}
6+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"parent": "item/generated",
3+
"textures": {
4+
"layer0": "miapi:item/arrow/tail/default"
5+
}
6+
}
Loading

0 commit comments

Comments
 (0)