Skip to content

Commit

Permalink
Finish up!
Browse files Browse the repository at this point in the history
  • Loading branch information
Patbox committed Feb 23, 2024
1 parent a91400b commit 2da081d
Show file tree
Hide file tree
Showing 15 changed files with 335 additions and 23 deletions.
1 change: 1 addition & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ko_fi: Patbox
23 changes: 11 additions & 12 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,37 @@
# against bad commits.

name: build
on: [pull_request, push]
on:
pull_request:
push:
paths-ignore: [ '.github/', 'docs/', 'mkdocs.yml' ]

jobs:
build:
strategy:
matrix:
# Use these Java versions
java: [
17, # Current Java LTS & minimum supported by Minecraft
21, # Current Java LTS
17 # Latest version
]
# and run on both Linux and Windows
os: [ubuntu-22.04, windows-2022]
os: [ubuntu-latest]
runs-on: ${{ matrix.os }}
steps:
- name: checkout repository
uses: actions/checkout@v4
- name: validate gradle wrapper
uses: gradle/wrapper-validation-action@v1
uses: actions/checkout@v2
- name: setup jdk ${{ matrix.java }}
uses: actions/setup-java@v4
uses: actions/setup-java@v1
with:
java-version: ${{ matrix.java }}
distribution: 'microsoft'
- name: make gradle wrapper executable
if: ${{ runner.os != 'Windows' }}
run: chmod +x ./gradlew
- name: build
run: ./gradlew build
- name: capture build artifacts
if: ${{ runner.os == 'Linux' && matrix.java == '21' }} # Only upload artifacts built from latest java on one OS
uses: actions/upload-artifact@v3
if: ${{ runner.os == 'Linux' && matrix.java == '17' }} # Only upload artifacts built from LTS java on one OS
uses: actions/upload-artifact@v2
with:
name: Artifacts
path: build/libs/
path: build/libs/
36 changes: 36 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Release

on:
release:
types:
- published
workflow_dispatch:

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/cache@v2
with:
path: |
~/.gradle/loom-cache
~/.gradle/caches
~/.gradle/wrapper
key: gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
gradle-
- uses: actions/checkout@v2
- name: Set up JDK
uses: actions/setup-java@v1
with:
java-version: 17

- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Build and publish with Gradle
run: ./gradlew build publish
env:
MODRINTH: ${{ secrets.MODRINTH }}
CHANGELOG: ${{ github.event.release.body }}
RELEASE: true
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Polymer Patch for Anshar
This mod is a patch/addon to [Anshar by hama Industries](https://modrinth.com/mod/anshar), allowing it to function purely server side.
Anshar mod is required and not included within this mod.

[You can read more about Anshar on it's Modrinth page!](https://modrinth.com/mod/anshar)

## [== Download on Modrinth ==](https://modrinth.com/project/anshar-polymer)
26 changes: 23 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
plugins {
id 'fabric-loom' version '1.5-SNAPSHOT'
id 'maven-publish'
id "com.modrinth.minotaur" version "2.+"
}

version = project.mod_version
Expand Down Expand Up @@ -44,9 +45,7 @@ dependencies {
modImplementation "dev.onyxstudios.cardinal-components-api:cardinal-components-entity:5.4.0"
modImplementation "fuzs.forgeconfigapiport:forgeconfigapiport-fabric:20.4.2"

modImplementation 'eu.pb4:polymer-resource-pack:0.7.5+1.20.4'
modImplementation 'eu.pb4:polymer-autohost:0.7.5+1.20.4'
modImplementation include('eu.pb4:polymer-virtual-entity:0.7.5+1.20.4')
modImplementation include('eu.pb4:polymer-virtual-entity:0.7.6+1.20.4')
modImplementation include("xyz.nucleoid:server-translations-api:2.2.0+1.20.3-rc1")

// Uncomment the following line to enable the deprecated Fabric API modules.
Expand Down Expand Up @@ -98,4 +97,25 @@ publishing {
// The repositories here will be used for publishing your artifact, not for
// retrieving dependencies.
}
}

if (System.getenv("MODRINTH")) {
modrinth {
token = System.getenv("MODRINTH")
projectId = 'wHXli9kE'// The ID of your modrinth project, slugs will not work.
versionNumber = "" + version // The version of the mod to upload.
versionType = "release"
uploadFile = remapJar // This links to a task that builds your mod jar and sets "uploadFile" to the mod jar.
gameVersions = [((String) project.minecraft_version)]
changelog = System.getenv("CHANGELOG")
loaders = ["fabric", "quilt"]

dependencies {
required.project "anshar"
}
}

remapJar {
finalizedBy project.tasks.modrinth
}
}
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ yarn_mappings=1.20.4+build.3
loader_version=0.15.6

# Mod Properties
mod_version=0.0.15
mod_version=0.0.15.0
maven_group=eu.pb4.ansharpatch
archives_base_name=anshar-polymer-patch

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package eu.pb4.ansharpatch.mixin;

import net.minecraft.network.packet.s2c.play.EntityStatusS2CPacket;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Mutable;
import org.spongepowered.asm.mixin.gen.Accessor;

@Mixin(EntityStatusS2CPacket.class)
public interface EntityStatusS2CPacketAccessor {
@Accessor
int getId();

@Mutable
@Accessor
void setId(int id);

@Accessor
byte getStatus();

@Mutable
@Accessor
void setStatus(byte status);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package eu.pb4.ansharpatch.mixin;

import net.minecraft.resource.FileResourcePackProvider;
import net.minecraft.resource.ResourcePackSource;
import net.minecraft.resource.ResourceType;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;

@Mixin(FileResourcePackProvider.class)
public interface FileResourcePackProviderAccessor {

@Accessor
ResourcePackSource getSource();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package eu.pb4.ansharpatch.mixin;

import net.minecraft.entity.data.TrackedData;
import net.minecraft.entity.projectile.FireworkRocketEntity;
import net.minecraft.item.ItemStack;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;

@Mixin(FireworkRocketEntity.class)
public interface FireworkRocketEntityAccessor {
@Accessor
static TrackedData<ItemStack> getITEM() {
throw new UnsupportedOperationException();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,34 @@
import com.lgmrszd.anshar.beacon.BeaconNode;
import com.lgmrszd.anshar.frequency.FrequencyNetwork;
import com.lgmrszd.anshar.transport.PlayerTransportComponent;
import com.lgmrszd.anshar.transport.TransportEffects;
import eu.pb4.polymer.common.api.PolymerCommonUtils;
import eu.pb4.polymer.virtualentity.api.ElementHolder;
import eu.pb4.polymer.virtualentity.api.VirtualEntityUtils;
import eu.pb4.polymer.virtualentity.api.attachment.HolderAttachment;
import eu.pb4.polymer.virtualentity.api.elements.BlockDisplayElement;
import eu.pb4.polymer.virtualentity.api.elements.ItemDisplayElement;
import it.unimi.dsi.fastutil.ints.IntArrayList;
import net.minecraft.client.render.model.json.ModelTransformationMode;
import net.minecraft.entity.EntityStatuses;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.data.DataTracker;
import net.minecraft.entity.decoration.Brightness;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.FireworkRocketItem;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.network.listener.ClientPlayPacketListener;
import net.minecraft.network.packet.Packet;
import net.minecraft.network.packet.s2c.play.*;
import net.minecraft.particle.DustParticleEffect;
import net.minecraft.particle.ParticleEffect;
import net.minecraft.particle.ParticleTypes;
import net.minecraft.registry.Registries;
import net.minecraft.server.network.ServerPlayNetworkHandler;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.sound.SoundCategory;
import net.minecraft.sound.SoundEvents;
import net.minecraft.text.Text;
import net.minecraft.util.math.BlockPos;
Expand All @@ -35,9 +47,7 @@
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import java.util.Collection;
import java.util.List;
import java.util.Set;
import java.util.*;


@Mixin(PlayerTransportComponent.class)
Expand Down Expand Up @@ -68,6 +78,8 @@ public abstract class PlayerTransportComponentMixin implements HolderAttachment

@Shadow public abstract boolean isInNetwork();

@Shadow public abstract void serverTick();

@Unique
private static final int TICKS_TO_JUMP = 230;
@Unique
Expand Down Expand Up @@ -162,13 +174,19 @@ public void onTick(CallbackInfo ci) {
}

if (this.nearest != null) {
if (this.gateTicks % 40 == 0) {
this.serverPlayer.networkHandler.sendPacket(new PlaySoundS2CPacket(Registries.SOUND_EVENT.getEntry(SoundEvents.BLOCK_BEACON_AMBIENT), SoundCategory.BLOCKS,
serverPlayer.getX(), serverPlayer.getY(), serverPlayer.getZ(), 0.8f, 2f, 0l));
}
++this.gateTicks;

}
} else {
this.gateTicks = 0;
this.nearest = null;
//this.audioManager.stopJump();
//this.spawnOrientationParticles();
this.serverPlayer.networkHandler.sendPacket(new StopSoundS2CPacket(SoundEvents.BLOCK_BEACON_AMBIENT.getId(), SoundCategory.BLOCKS));
}
var helpColr = 7368816;

Expand Down Expand Up @@ -260,14 +278,33 @@ private void replaceTeleport(PlayerEntity instance, double x, double y, double z
*/
@Overwrite
public void sendExplosionPacketS2C(boolean skipOurselves, BlockPos pos, int color) {
var list = new ArrayList<Packet<ClientPlayPacketListener>>();
var id = VirtualEntityUtils.requestEntityId();
list.add(new EntitySpawnS2CPacket(id, UUID.randomUUID(),
pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, 0, 0, EntityType.FIREWORK_ROCKET, 0, Vec3d.ZERO, 0));

{
var stack = new ItemStack(Items.FIREWORK_ROCKET);
stack.getOrCreateNbt().put(FireworkRocketItem.FIREWORKS_KEY, TransportEffects.makeTransportFirework(color));
list.add(new EntityTrackerUpdateS2CPacket(id, List.of(DataTracker.SerializedEntry.of(FireworkRocketEntityAccessor.getITEM(), stack))));
}
{
var x = PolymerCommonUtils.createUnsafe(EntityStatusS2CPacket.class);
((EntityStatusS2CPacketAccessor) x).setId(id);
((EntityStatusS2CPacketAccessor) x).setStatus(EntityStatuses.EXPLODE_FIREWORK_CLIENT);
list.add(x);
}
list.add(new EntitiesDestroyS2CPacket(id));

var b = new BundleS2CPacket(list);

for (var player : this.player.getWorld().getPlayers()) {
if (skipOurselves && player == this.player) {
continue;
}

if (player instanceof ServerPlayerEntity serverPlayer && this.player.getPos().isInRange(player.getPos(), 32.0)) {
serverPlayer.networkHandler.sendPacket(new ExplosionS2CPacket(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, 3, List.of(),
Vec3d.ZERO, Explosion.DestructionType.KEEP, ParticleTypes.FIREWORK, ParticleTypes.FIREWORK, SoundEvents.INTENTIONALLY_EMPTY));
serverPlayer.networkHandler.sendPacket(b);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package eu.pb4.ansharpatch.mixin;

import eu.pb4.ansharpatch.pack.LangPackProvider;
import net.minecraft.resource.*;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Mutable;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;

@Mixin(ResourcePackManager.class)
public abstract class ResourcePackManagerMixin {

@Shadow
@Final
@Mutable
public Set<ResourcePackProvider> providers;

@Inject(method = "<init>", at = @At("RETURN"))
public void injectCustom(ResourcePackProvider[] resourcePackProviders, CallbackInfo info) {
providers = new LinkedHashSet<>(providers);

// Search resource pack providers to find any server-related pack provider.
boolean shouldAddServerProvider = false;

for (ResourcePackProvider provider : this.providers) {
if (provider instanceof FileResourcePackProvider
&& (((FileResourcePackProviderAccessor) provider).getSource() == ResourcePackSource.WORLD
|| ((FileResourcePackProviderAccessor) provider).getSource() == ResourcePackSource.SERVER)) {
shouldAddServerProvider = true;
break;
}
}

// On server, add the mod resource pack provider.
if (shouldAddServerProvider) {
providers.add(LangPackProvider.INSTANCE);
}
}
}
Loading

0 comments on commit 2da081d

Please sign in to comment.