Skip to content

Commit

Permalink
update to 1.21
Browse files Browse the repository at this point in the history
  • Loading branch information
ewewukek committed Jul 25, 2024
1 parent cf99ced commit 15befbf
Show file tree
Hide file tree
Showing 26 changed files with 73 additions and 68 deletions.
2 changes: 1 addition & 1 deletion fabric/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id 'fabric-loom' version '1.6-SNAPSHOT'
id 'fabric-loom' version '1.7-SNAPSHOT'
}

file("../gradle.properties").withInputStream {
Expand Down
2 changes: 1 addition & 1 deletion fabric/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
2 changes: 1 addition & 1 deletion fabric/gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
Expand Down
6 changes: 3 additions & 3 deletions fabric/src/main/java/ewewukek/musketmod/ClientSetup.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ public void onInitializeClient() {
ClampedItemPropertyFunction loaded = (stack, world, player, seed) -> {
return GunItem.isLoaded(stack) ? 1 : 0;
};
ItemProperties.register(Items.MUSKET, new ResourceLocation("loaded"), loaded);
ItemProperties.register(Items.MUSKET_WITH_BAYONET, new ResourceLocation("loaded"), loaded);
ItemProperties.register(Items.PISTOL, new ResourceLocation("loaded"), loaded);
ItemProperties.register(Items.MUSKET, ResourceLocation.fromNamespaceAndPath(MusketMod.MODID, "loaded"), loaded);
ItemProperties.register(Items.MUSKET_WITH_BAYONET, ResourceLocation.fromNamespaceAndPath(MusketMod.MODID, "loaded"), loaded);
ItemProperties.register(Items.PISTOL, ResourceLocation.fromNamespaceAndPath(MusketMod.MODID, "loaded"), loaded);

ClientPlayNetworking.registerGlobalReceiver(SmokeEffectPacket.TYPE, (packet, context) -> {
Vec3 origin = new Vec3(packet.origin());
Expand Down
18 changes: 9 additions & 9 deletions fabric/src/main/java/ewewukek/musketmod/MusketMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ public class MusketMod implements ModInitializer {
public void onInitialize() {
Config.reload();

Registry.register(BuiltInRegistries.DATA_COMPONENT_TYPE, new ResourceLocation(MODID, "loaded"), GunItem.LOADED);
Registry.register(BuiltInRegistries.DATA_COMPONENT_TYPE, new ResourceLocation(MODID, "loading_stage"), GunItem.LOADING_STAGE);
Registry.register(BuiltInRegistries.DATA_COMPONENT_TYPE, ResourceLocation.fromNamespaceAndPath(MODID, "loaded"), GunItem.LOADED);
Registry.register(BuiltInRegistries.DATA_COMPONENT_TYPE, ResourceLocation.fromNamespaceAndPath(MODID, "loading_stage"), GunItem.LOADING_STAGE);

Registry.register(BuiltInRegistries.ITEM, new ResourceLocation(MODID, "musket"), Items.MUSKET);
Registry.register(BuiltInRegistries.ITEM, new ResourceLocation(MODID, "musket_with_bayonet"), Items.MUSKET_WITH_BAYONET);
Registry.register(BuiltInRegistries.ITEM, new ResourceLocation(MODID, "pistol"), Items.PISTOL);
Registry.register(BuiltInRegistries.ITEM, new ResourceLocation(MODID, "cartridge"), Items.CARTRIDGE);
Registry.register(BuiltInRegistries.ITEM, ResourceLocation.fromNamespaceAndPath(MODID, "musket"), Items.MUSKET);
Registry.register(BuiltInRegistries.ITEM, ResourceLocation.fromNamespaceAndPath(MODID, "musket_with_bayonet"), Items.MUSKET_WITH_BAYONET);
Registry.register(BuiltInRegistries.ITEM, ResourceLocation.fromNamespaceAndPath(MODID, "pistol"), Items.PISTOL);
Registry.register(BuiltInRegistries.ITEM, ResourceLocation.fromNamespaceAndPath(MODID, "cartridge"), Items.CARTRIDGE);

ItemGroupEvents.modifyEntriesEvent(CreativeModeTabs.COMBAT).register(entries -> {
entries.accept(Items.MUSKET);
Expand All @@ -59,7 +59,7 @@ public void onInitialize() {
entries.accept(Items.CARTRIDGE);
});

Registry.register(BuiltInRegistries.ENTITY_TYPE, new ResourceLocation(MODID, "bullet"), BULLET_ENTITY_TYPE);
Registry.register(BuiltInRegistries.ENTITY_TYPE, ResourceLocation.fromNamespaceAndPath(MODID, "bullet"), BULLET_ENTITY_TYPE);

Registry.register(BuiltInRegistries.SOUND_EVENT, Sounds.MUSKET_LOAD_0.getLocation(), Sounds.MUSKET_LOAD_0);
Registry.register(BuiltInRegistries.SOUND_EVENT, Sounds.MUSKET_LOAD_1.getLocation(), Sounds.MUSKET_LOAD_1);
Expand All @@ -73,7 +73,7 @@ public void onInitialize() {
ResourceManagerHelper.get(PackType.SERVER_DATA).registerReloadListener(new IdentifiableResourceReloadListener() {
@Override
public ResourceLocation getFabricId() {
return new ResourceLocation(MODID, "reload");
return ResourceLocation.fromNamespaceAndPath(MODID, "reload");
}

@Override
Expand All @@ -88,7 +88,7 @@ public CompletableFuture<Void> reload(PreparationBarrier stage, ResourceManager
});
}

public static final ResourceLocation SMOKE_EFFECT_PACKET_ID = new ResourceLocation(MODID, "smoke_effect");
public static final ResourceLocation SMOKE_EFFECT_PACKET_ID = ResourceLocation.fromNamespaceAndPath(MODID, "smoke_effect");

public static void sendSmokeEffect(LivingEntity shooter, Vec3 origin, Vec3 direction) {
SmokeEffectPacket packet = SmokeEffectPacket.fromVec3(origin, direction);
Expand Down
4 changes: 2 additions & 2 deletions fabric/src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
"musketmod.mixins.json"
],
"depends": {
"fabricloader": ">=0.15.10",
"fabricloader": ">=0.15.11",
"fabric-api": "*",
"minecraft": "~1.20.6",
"minecraft": "~1.21",
"java": ">=21"
}
}
6 changes: 3 additions & 3 deletions forge/src/main/java/ewewukek/musketmod/ClientSetup.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ public static void init(final FMLClientSetupEvent event) {
ClampedItemPropertyFunction loaded = (stack, world, player, arg) -> {
return GunItem.isLoaded(stack) ? 1 : 0;
};
ItemProperties.register(Items.MUSKET, new ResourceLocation("loaded"), loaded);
ItemProperties.register(Items.MUSKET_WITH_BAYONET, new ResourceLocation("loaded"), loaded);
ItemProperties.register(Items.PISTOL, new ResourceLocation("loaded"), loaded);
ItemProperties.register(Items.MUSKET, ResourceLocation.fromNamespaceAndPath(MusketMod.MODID, "loaded"), loaded);
ItemProperties.register(Items.MUSKET_WITH_BAYONET, ResourceLocation.fromNamespaceAndPath(MusketMod.MODID, "loaded"), loaded);
ItemProperties.register(Items.PISTOL, ResourceLocation.fromNamespaceAndPath(MusketMod.MODID, "loaded"), loaded);
}

@SubscribeEvent(priority = EventPriority.LOW)
Expand Down
2 changes: 1 addition & 1 deletion forge/src/main/java/ewewukek/musketmod/MusketMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public class MusketMod {

private static final int PROTOCOL_VERSION = 2;
public static final SimpleChannel NETWORK_CHANNEL = ChannelBuilder.named(
new ResourceLocation(MODID, "main"))
ResourceLocation.fromNamespaceAndPath(MODID, "main"))
.networkProtocolVersion(PROTOCOL_VERSION)
.clientAcceptedVersions(Channel.VersionTest.exact(PROTOCOL_VERSION))
.serverAcceptedVersions(Channel.VersionTest.exact(PROTOCOL_VERSION))
Expand Down
8 changes: 4 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ mod_name=musketmod
mod_version=1.4.8
maven_group=ewewukek.musketmod

minecraft_version=1.20.6
minecraft_version=1.21

forge_version=1.20.6-50.1.0
forge_version=1.21-51.0.26

fabric_loader_version=0.15.10
fabric_version=0.97.8+1.20.6
fabric_loader_version=0.15.11
fabric_version=0.100.3+1.21
15 changes: 9 additions & 6 deletions src/main/java/ewewukek/musketmod/BulletEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import net.minecraft.network.syncher.SynchedEntityData;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerEntity;
import net.minecraft.tags.FluidTags;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.damagesource.DamageType;
Expand All @@ -33,9 +34,10 @@
import net.minecraft.world.phys.Vec3;

public class BulletEntity extends AbstractHurtingProjectile {
// workaround for ClientboundAddEntityPacket.LIMIT
public static final EntityDataAccessor<Float> INITIAL_SPEED = SynchedEntityData.defineId(BulletEntity.class, EntityDataSerializers.FLOAT);

public static final ResourceKey<DamageType> BULLET_DAMAGE = ResourceKey.create(Registries.DAMAGE_TYPE, new ResourceLocation(MusketMod.MODID, "bullet"));
public static final ResourceKey<DamageType> BULLET_DAMAGE = ResourceKey.create(Registries.DAMAGE_TYPE, ResourceLocation.fromNamespaceAndPath(MusketMod.MODID, "bullet"));

public static final double MIN_DAMAGE = 0.5;
public static final double GRAVITY = 0.05;
Expand Down Expand Up @@ -288,15 +290,16 @@ public void addAdditionalSaveData(CompoundTag compound) {

// workaround for ClientboundAddEntityPacket.LIMIT
@Override
public Packet<ClientGamePacketListener> getAddEntityPacket() {
public Packet<ClientGamePacketListener> getAddEntityPacket(ServerEntity entity) {
Entity owner = getOwner();
Vec3 position = entity.getPositionBase();
return new ClientboundAddEntityPacket(
getId(), getUUID(),
getX(), getY(), getZ(),
getXRot(), getYRot(),
position.x(), position.y(), position.z(),
entity.getLastSentXRot(), entity.getLastSentYRot(),
getType(), owner != null ? owner.getId() : 0,
getDeltaMovement().scale(4.0 / entityData.get(INITIAL_SPEED)),
getYHeadRot()
entity.getLastSentMovement().scale(4.0 / entityData.get(INITIAL_SPEED)),
0
);
}

Expand Down
44 changes: 23 additions & 21 deletions src/main/java/ewewukek/musketmod/BulletRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
import net.minecraft.resources.ResourceLocation;

public class BulletRenderer extends EntityRenderer<BulletEntity> {
public static final ResourceLocation TEXTURE = new ResourceLocation(MusketMod.MODID + ":textures/entity/bullet.png");
public static final ResourceLocation TEXTURE = ResourceLocation.fromNamespaceAndPath(MusketMod.MODID, "textures/entity/bullet.png");
public static final RenderType RENDER_TYPE = RenderType.entityCutoutNoCull(TEXTURE);

public BulletRenderer(EntityRendererProvider.Context ctx) {
super(ctx);
Expand All @@ -24,34 +25,35 @@ public ResourceLocation getTextureLocation(BulletEntity bullet) {
}

@Override
public void render(BulletEntity bullet, float yaw, float partialTicks, PoseStack matrixStack, MultiBufferSource render, int packedLight) {
public void render(BulletEntity bullet, float yaw, float partialTicks, PoseStack poseStack, MultiBufferSource render, int light) {
if (bullet.isFirstTick()) return;

matrixStack.pushPose();
poseStack.pushPose();

matrixStack.scale(0.1f, 0.1f, 0.1f);
poseStack.scale(0.1f, 0.1f, 0.1f);
// billboarding
matrixStack.mulPose(entityRenderDispatcher.cameraOrientation());
matrixStack.mulPose(Axis.YP.rotationDegrees(180));
poseStack.mulPose(entityRenderDispatcher.cameraOrientation());
poseStack.mulPose(Axis.YP.rotationDegrees(180));

PoseStack.Pose pose = matrixStack.last();
VertexConsumer builder = render.getBuffer(RenderType.entityCutout(getTextureLocation(bullet)));
PoseStack.Pose pose = poseStack.last();
VertexConsumer builder = render.getBuffer(RENDER_TYPE);

addVertex(builder, pose, -1, -1, 0, 0, 1, 0, 0, 1, packedLight);
addVertex(builder, pose, 1, -1, 0, 1, 1, 0, 0, 1, packedLight);
addVertex(builder, pose, 1, 1, 0, 1, 0, 0, 0, 1, packedLight);
addVertex(builder, pose, -1, 1, 0, 0, 0, 0, 0, 1, packedLight);
addVertex(builder, pose, -1, -1, 0, 0, 1, 0, 0, 1, light);
addVertex(builder, pose, 1, -1, 0, 1, 1, 0, 0, 1, light);
addVertex(builder, pose, 1, 1, 0, 1, 0, 0, 0, 1, light);
addVertex(builder, pose, -1, 1, 0, 0, 0, 0, 0, 1, light);

matrixStack.popPose();
poseStack.popPose();

super.render(bullet, yaw, partialTicks, poseStack, render, light);
}

void addVertex(VertexConsumer builder, PoseStack.Pose pose, float x, float y, float z, float u, float v, float nx, float ny, float nz, int packedLight) {
builder.vertex(pose, x, y, z)
.color(255, 255, 255, 255)
.uv(u, v)
.overlayCoords(OverlayTexture.NO_OVERLAY)
.uv2(packedLight)
.normal(pose, nx, ny, nz)
.endVertex();
void addVertex(VertexConsumer builder, PoseStack.Pose pose, float x, float y, float z, float u, float v, float nx, float ny, float nz, int light) {
builder.addVertex(pose, x, y, z)
.setColor(255, 255, 255, 255)
.setUv(u, v)
.setOverlay(OverlayTexture.NO_OVERLAY)
.setLight(light)
.setNormal(pose, nx, ny, nz);
}
}
2 changes: 1 addition & 1 deletion src/main/java/ewewukek/musketmod/ClientUtilities.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public static void renderGunInHand(ItemInHandRenderer renderer, AbstractClientPl
}

} else if (player.isUsingItem() && player.getUsedItemHand() == hand) {
float usingDuration = stack.getUseDuration() - (player.getUseItemRemainingTicks() - partialTicks + 1);
float usingDuration = stack.getUseDuration(player) - (player.getUseItemRemainingTicks() - partialTicks + 1);
if (usingDuration > 0 && usingDuration < GunItem.RELOAD_DURATION) {
matrixStack.translate(0, -0.3, 0.05);
matrixStack.mulPose(Axis.XP.rotationDegrees(60));
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/ewewukek/musketmod/GunItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public void releaseUsing(ItemStack stack, Level worldIn, LivingEntity entityLivi

@Override
public void onUseTick(Level world, LivingEntity entity, ItemStack stack, int timeLeft) {
int usingDuration = getUseDuration(stack) - timeLeft;
int usingDuration = getUseDuration(stack, entity) - timeLeft;
int loadingStage = getLoadingStage(stack);

if (loadingStage == 1 && usingDuration >= LOADING_STAGE_1) {
Expand Down Expand Up @@ -186,7 +186,7 @@ public boolean mineBlock(ItemStack stack, Level worldIn, BlockState state, Block
}

@Override
public int getUseDuration(ItemStack stack) {
public int getUseDuration(ItemStack stack, LivingEntity entity) {
return 72000;
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/ewewukek/musketmod/MusketItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ public MusketItem(Item.Properties properties) {
public static ItemAttributeModifiers createBayonetAttributes() {
return ItemAttributeModifiers.builder()
.add(Attributes.ATTACK_DAMAGE, new AttributeModifier(
BASE_ATTACK_DAMAGE_UUID, "Weapon modifier", bayonetDamage, AttributeModifier.Operation.ADD_VALUE),
BASE_ATTACK_DAMAGE_ID, bayonetDamage, AttributeModifier.Operation.ADD_VALUE),
EquipmentSlotGroup.MAINHAND)
.add(Attributes.ATTACK_SPEED, new AttributeModifier(
BASE_ATTACK_SPEED_UUID, "Weapon modifier", BAYONET_SPEED, AttributeModifier.Operation.ADD_VALUE),
BASE_ATTACK_SPEED_ID, BAYONET_SPEED, AttributeModifier.Operation.ADD_VALUE),
EquipmentSlotGroup.MAINHAND)
.build();
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/ewewukek/musketmod/SmokeEffectPacket.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

public record SmokeEffectPacket(Vector3f origin, Vector3f direction) implements CustomPacketPayload {
public static final CustomPacketPayload.Type<SmokeEffectPacket> TYPE =
new CustomPacketPayload.Type<>(new ResourceLocation(MusketMod.MODID, "smoke"));
new CustomPacketPayload.Type<>(ResourceLocation.fromNamespaceAndPath(MusketMod.MODID, "smoke"));
public static final StreamCodec<ByteBuf, SmokeEffectPacket> CODEC =
StreamCodec.composite(
ByteBufCodecs.VECTOR3F, SmokeEffectPacket::origin,
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/ewewukek/musketmod/Sounds.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
import net.minecraft.sounds.SoundEvent;

public class Sounds {
public static final SoundEvent MUSKET_LOAD_0 = SoundEvent.createVariableRangeEvent(new ResourceLocation(MusketMod.MODID, "musket_load0"));
public static final SoundEvent MUSKET_LOAD_1 = SoundEvent.createVariableRangeEvent(new ResourceLocation(MusketMod.MODID, "musket_load1"));
public static final SoundEvent MUSKET_LOAD_2 = SoundEvent.createVariableRangeEvent(new ResourceLocation(MusketMod.MODID, "musket_load2"));
public static final SoundEvent MUSKET_READY = SoundEvent.createVariableRangeEvent(new ResourceLocation(MusketMod.MODID, "musket_ready"));
public static final SoundEvent MUSKET_FIRE = SoundEvent.createVariableRangeEvent(new ResourceLocation(MusketMod.MODID, "musket_fire"));
public static final SoundEvent PISTOL_FIRE = SoundEvent.createVariableRangeEvent(new ResourceLocation(MusketMod.MODID, "pistol_fire"));
public static final SoundEvent MUSKET_LOAD_0 = SoundEvent.createVariableRangeEvent(ResourceLocation.fromNamespaceAndPath(MusketMod.MODID, "musket_load0"));
public static final SoundEvent MUSKET_LOAD_1 = SoundEvent.createVariableRangeEvent(ResourceLocation.fromNamespaceAndPath(MusketMod.MODID, "musket_load1"));
public static final SoundEvent MUSKET_LOAD_2 = SoundEvent.createVariableRangeEvent(ResourceLocation.fromNamespaceAndPath(MusketMod.MODID, "musket_load2"));
public static final SoundEvent MUSKET_READY = SoundEvent.createVariableRangeEvent(ResourceLocation.fromNamespaceAndPath(MusketMod.MODID, "musket_ready"));
public static final SoundEvent MUSKET_FIRE = SoundEvent.createVariableRangeEvent(ResourceLocation.fromNamespaceAndPath(MusketMod.MODID, "musket_fire"));
public static final SoundEvent PISTOL_FIRE = SoundEvent.createVariableRangeEvent(ResourceLocation.fromNamespaceAndPath(MusketMod.MODID, "pistol_fire"));
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"overrides": [
{
"predicate": {
"loaded": 1
"musketmod:loaded": 1
},
"model": "musketmod:item/musket_loaded"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"overrides": [
{
"predicate": {
"loaded": 1
"musketmod:loaded": 1
},
"model": "musketmod:item/musket_with_bayonet_loaded"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"overrides": [
{
"predicate": {
"loaded": 1
"musketmod:loaded": 1
},
"model": "musketmod:item/pistol_loaded"
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/pack.mcmeta
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"pack": {
"description": "musketmod resources",
"pack_format": 32
"pack_format": 34
}
}

0 comments on commit 15befbf

Please sign in to comment.