Skip to content

Commit

Permalink
Merge pull request #306 from H0Imes/1.18.x
Browse files Browse the repository at this point in the history
Bug Fixes
  • Loading branch information
0xE69 authored Oct 31, 2024
2 parents 70b8e34 + 2dc2b4f commit bf7f26c
Show file tree
Hide file tree
Showing 59 changed files with 386 additions and 223 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
"accuracy_percent": 0.9,
"recoil": 1.5,
"fire_delay_ms": 2000,
"damage": 7.0,
"damage": 2.0,
"reload_duration_ticks": 60
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,11 @@ private void onKeyPress(long windowPointer, int key, int scancode, int action, i
CallbackInfo ci) {

var minecraft = Minecraft.getInstance();
var playerExtension = PlayerExtension.get(minecraft.player);
if (minecraft.player == null) {
return;
}

var playerExtension = PlayerExtension.get(minecraft.player);
if (playerExtension == null) {
return;
}
Expand Down Expand Up @@ -69,3 +72,4 @@ private void onKeyPress(long windowPointer, int key, int scancode, int action, i
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@

import java.util.function.Supplier;

public class DamageHandcuffsMessage {

public DamageHandcuffsMessage() {
}
public record DamageHandcuffsMessage() {

public void encode(FriendlyByteBuf buf) {
}
Expand All @@ -51,3 +48,4 @@ public void handle(Supplier<NetworkEvent.Context> contextSupplier) {
context.setPacketHandled(true);
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,11 @@
import net.minecraft.world.entity.LivingEntity;
import net.minecraftforge.network.NetworkEvent;

public class ParachuteSyncMessage {

private final int entityId;
private final boolean hasParachute;

public ParachuteSyncMessage(int entityId, boolean hasParachute) {
this.entityId = entityId;
this.hasParachute = hasParachute;
}
public record ParachuteSyncMessage(int entityId, boolean hasParachute) {

public static void encode(ParachuteSyncMessage packet, FriendlyByteBuf buf) {
buf.writeInt(packet.entityId);
buf.writeBoolean(packet.hasParachute);
buf.writeInt(packet.entityId());
buf.writeBoolean(packet.hasParachute());
}

public static ParachuteSyncMessage decode(FriendlyByteBuf buf) {
Expand All @@ -49,9 +41,9 @@ public static ParachuteSyncMessage decode(FriendlyByteBuf buf) {
public static void handle(ParachuteSyncMessage packet, Supplier<NetworkEvent.Context> context) {
context.get().enqueueWork(() -> {
assert Minecraft.getInstance().level != null;
Entity entity = Minecraft.getInstance().level.getEntity(packet.entityId);
Entity entity = Minecraft.getInstance().level.getEntity(packet.entityId());
if (entity instanceof LivingEntity livingEntity) {
if (packet.hasParachute) {
if (packet.hasParachute()) {
livingEntity.addEffect(new MobEffectInstance(ModMobEffects.PARACHUTE.get()));
} else {
livingEntity.removeEffect(ModMobEffects.PARACHUTE.get());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,31 @@

package com.craftingdead.core.world.action;

import java.util.Optional;
import java.util.function.Supplier;
import com.craftingdead.core.CraftingDead;
import com.craftingdead.core.tags.ModItemTags;
import com.craftingdead.core.world.action.item.BlockItemActionType;
import com.craftingdead.core.world.action.item.EntityItemActionType;
import com.craftingdead.core.world.action.reload.MagazineReloadAction;
import com.craftingdead.core.world.action.reload.RefillableReloadAction;
import com.craftingdead.core.world.effect.ModMobEffects;
import com.craftingdead.core.world.entity.extension.PlayerExtension;
import com.craftingdead.core.world.item.ModItems;
import com.google.common.base.Predicates;
import java.util.Optional;
import java.util.function.Predicate;
import java.util.function.Supplier;
import net.minecraft.ChatFormatting;
import net.minecraft.core.Registry;
import net.minecraft.network.chat.TranslatableComponent;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.tags.FluidTags;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.effect.MobEffectInstance;
import net.minecraft.world.effect.MobEffects;
import net.minecraft.world.entity.monster.Skeleton;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.IForgeRegistry;
import net.minecraftforge.registries.RegistryBuilder;
Expand Down Expand Up @@ -68,6 +73,26 @@ public class ActionTypes {
deferredRegister.register("remove_magazine",
() -> new SimpleActionType<>(RemoveMagazineAction::new, true));

public static final RegistryObject<EntityItemActionType<?>> SHRED_CLOTHING =
deferredRegister.register("shred_clothing",
() -> EntityItemActionType.builder(TargetSelector.SELF_ONLY)
.forItem(itemStack -> itemStack.is(ModItemTags.CLOTHING))
.customAction((performer, target) -> {
var random = target.random();
int randomRagAmount = random.nextInt(3) + 3;

for (int i = 0; i < randomRagAmount; i++) {
if (random.nextBoolean()) {
target.entity().spawnAtLocation(
new ItemStack(ModItems.CLEAN_RAG::get));
} else {
target.entity().spawnAtLocation(
new ItemStack(ModItems.DIRTY_RAG::get));
}
}
}, 1.0F)
.build());

public static final RegistryObject<EntityItemActionType<?>> USE_SYRINGE =
deferredRegister.register("use_syringe",
() -> EntityItemActionType
Expand All @@ -80,7 +105,7 @@ public class ActionTypes {

var targetEntity = target.entity();
if (targetEntity.getHealth() > 4) {
return Optional.ofNullable(target);
return Optional.of(target);
}

if (performer.entity() instanceof Player player) {
Expand Down Expand Up @@ -135,11 +160,31 @@ public class ActionTypes {
.effect(() -> new MobEffectInstance(MobEffects.HEAL, 1, 0))
.build());

public static final RegistryObject<EntityItemActionType<?>> USE_CLEAN_RAG =
deferredRegister.register("use_clean_rag",
() -> EntityItemActionType
.builder(TargetSelector.SELF_OR_OTHERS.hasEffect(ModMobEffects.BLEEDING))
.forItem(ModItems.CLEAN_RAG)
.duration(16)
.resultItem(ModItems.BLOODY_RAG)
.build());

public static final RegistryObject<BlockItemActionType> WASH_RAG =
deferredRegister.register("wash_rag",
() -> BlockItemActionType.builder()
.forItem(itemStack -> itemStack.is(ModItems.DIRTY_RAG.get())
|| itemStack.is(ModItems.BLOODY_RAG.get()))
.resultItem(ModItems.CLEAN_RAG)
.consumeItemInCreative(true)
.finishSound(SoundEvents.BUCKET_FILL)
.forFluid(FluidTags.WATER)
.build());

public static final RegistryObject<EntityItemActionType<?>> APPLY_HANDCUFFS =
deferredRegister.register("apply_handcuffs",
() -> EntityItemActionType.builder(TargetSelector.OTHERS_ONLY
.players()
.filter(Predicates.not(PlayerExtension::isHandcuffed)))
.filter(((Predicate<PlayerExtension<?>>) PlayerExtension::isHandcuffed).negate()))
.forItem(ModItems.HANDCUFFS)
.customAction((performer, target) -> {
target.setHandcuffs(performer.mainHandItem().copy());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public class ModDamageSource {

public static final String BULLET_HEADSHOT_DAMAGE_TYPE = "bullet.headshot";
public static final String BULLET_BODY_DAMAGE_TYPE = "bullet";
public static final String BLEEDING = "bleeding";

public static DamageSource gun(LivingEntity source, boolean headshot) {
var messageId = headshot ? BULLET_HEADSHOT_DAMAGE_TYPE : BULLET_BODY_DAMAGE_TYPE;
Expand All @@ -43,6 +44,10 @@ public static DamageSource grenade(Grenade grenade, @Nullable Entity thrower) {
return new IndirectEntityDamageSource("grenade", grenade, thrower).setExplosion();
}

public static DamageSource bleeding() {
return new DamageSource(BLEEDING).bypassArmor();
}

/**
* Creates an explosion damage source without difficulty scaling.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@
* https://craftingdead.net/terms.php
*/

package com.craftingdead.survival.world.effect;
package com.craftingdead.core.world.effect;

import com.craftingdead.core.world.damagesource.ModDamageSource;
import java.util.ArrayList;
import java.util.List;
import com.craftingdead.core.world.item.ModItems;
import com.craftingdead.survival.world.damagesource.SurvivalDamageSource;
import com.craftingdead.survival.world.item.SurvivalItems;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.effect.MobEffect;
Expand All @@ -41,7 +40,7 @@ protected BleedingMobEffect() {
@Override
public void applyEffectTick(LivingEntity livingEntity, int amplifier) {
if (livingEntity.getHealth() > 1.0F) {
livingEntity.hurt(SurvivalDamageSource.BLEEDING, 1.0F);
livingEntity.hurt(ModDamageSource.bleeding(), 1.0F);
}
}

Expand All @@ -53,9 +52,9 @@ public boolean isDurationEffectTick(int duration, int amplifier) {

@Override
public List<ItemStack> getCurativeItems() {
List<ItemStack> items = new ArrayList<ItemStack>();
List<ItemStack> items = new ArrayList<>();
items.add(new ItemStack(ModItems.BANDAGE::get));
items.add(new ItemStack(SurvivalItems.CLEAN_RAG::get));
items.add(new ItemStack(ModItems.CLEAN_RAG::get));
items.add(new ItemStack(ModItems.FIRST_AID_KIT::get));
return items;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ public class ModMobEffects {
public static final RegistryObject<MobEffect> ADRENALINE =
deferredRegister.register("adrenaline", AdrenalineMobEffect::new);

public static final RegistryObject<MobEffect> BLEEDING =
deferredRegister.register("bleeding", BleedingMobEffect::new);

public static final RegistryObject<MobEffect> PARACHUTE =
deferredRegister.register("parachute", ParachuteMobEffect::new);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,22 @@

package com.craftingdead.core.world.item;

import com.craftingdead.core.world.action.item.ItemActionType;
import com.craftingdead.core.world.entity.extension.LivingExtension;
import com.craftingdead.core.world.entity.extension.PlayerExtension;
import java.util.List;
import java.util.Objects;
import java.util.UUID;
import java.util.function.Supplier;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.InteractionResultHolder;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.context.UseOnContext;
import net.minecraft.world.level.ClipContext;
import net.minecraft.world.phys.HitResult;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import com.craftingdead.core.capability.CapabilityUtil;
import com.craftingdead.core.world.item.equipment.Equipment;
Expand Down Expand Up @@ -47,12 +61,18 @@ public class ClothingItem extends EquipmentItem {
private final Multimap<Attribute, AttributeModifier> attributeModifiers;
private final boolean fireImmunity;
private final boolean enhancesSwimming;
private final Supplier<? extends ItemActionType<?>> itemActionType;

public ClothingItem(Properties properties) {
public ClothingItem(Properties properties, Supplier<? extends ItemActionType<?>> itemActionType) {
super(properties);
this.attributeModifiers = properties.attributeModifiers.build();
this.fireImmunity = properties.fireImmunity;
this.enhancesSwimming = properties.enhancesSwimming;
this.itemActionType = itemActionType;
}

public ItemActionType<?> getActionType() {
return this.itemActionType.get();
}

@Override
Expand All @@ -69,11 +89,69 @@ public void appendHoverText(ItemStack stack, Level world, List<Component> lines,
public ICapabilityProvider initCapabilities(ItemStack itemStack, @Nullable CompoundTag nbt) {
return CapabilityUtil.provider(
() -> new SimpleClothing(this.attributeModifiers, this.fireImmunity, this.enhancesSwimming,
new ResourceLocation(this.getRegistryName().getNamespace(), "textures/clothing/"
+ this.getRegistryName().getPath() + "_" + "default" + ".png")),
new ResourceLocation(Objects.requireNonNull(this.getRegistryName()).getNamespace(),
"textures/clothing/"
+ this.getRegistryName().getPath() + "_" + "default" + ".png")),
Equipment.CAPABILITY);
}

@Override
public @NotNull InteractionResult useOn(UseOnContext context) {
if (!context.getLevel().isClientSide()) {
var performer = PlayerExtension.getOrThrow(context.getPlayer());
if (this.getActionType().createBlockAction(performer, context)
.map(action -> performer.performAction(action, true))
.orElse(false)) {
return InteractionResult.CONSUME;
}
}
return InteractionResult.PASS;
}

@Override
public @NotNull InteractionResult interactLivingEntity(@NotNull ItemStack itemStack,
Player player, @NotNull LivingEntity targetEntity, @NotNull InteractionHand hand) {
if (!player.getLevel().isClientSide()) {
var performer = PlayerExtension.getOrThrow(player);
var target = LivingExtension.getOrThrow(targetEntity);
if (this.getActionType().createEntityAction(performer, target, hand)
.map(action -> performer.performAction(action, true))
.orElse(false)) {
return InteractionResult.CONSUME;
}
}
return InteractionResult.PASS;
}

@Override
public @NotNull InteractionResultHolder<ItemStack> use(@NotNull Level level, Player player,
@NotNull InteractionHand hand) {
if (!player.getLevel().isClientSide()) {
var performer = PlayerExtension.getOrThrow(player);
var hitResult = getPlayerPOVHitResult(level, player, ClipContext.Fluid.ANY);
if (hitResult.getType() == HitResult.Type.BLOCK
&& this.getActionType()
.createBlockAction(performer, new UseOnContext(player, hand, hitResult))
.map(action -> performer.performAction(action, true))
.orElse(false)) {
return InteractionResultHolder.consume(player.getItemInHand(hand));
}

if (this.getActionType().createAction(performer, hand)
.map(action -> performer.performAction(action, true))
.orElse(false)) {
return InteractionResultHolder.consume(player.getItemInHand(hand));
}
}

return InteractionResultHolder.pass(player.getItemInHand(hand));
}

@Override
public int getUseDuration(@NotNull ItemStack itemStack) {
return this.getActionType().getDurationTicks();
}

public static class Properties extends Item.Properties {

private final ImmutableMultimap.Builder<Attribute, AttributeModifier> attributeModifiers =
Expand Down
Loading

0 comments on commit bf7f26c

Please sign in to comment.