Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added settings.gradle
Empty file.
9 changes: 5 additions & 4 deletions src/main/java/com/alrex/parcool/ParCool.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@
import com.alrex.parcool.common.block.Blocks;
import com.alrex.parcool.common.block.TileEntities;
import com.alrex.parcool.common.capability.capabilities.Capabilities;
import com.alrex.parcool.common.entity.EntityType;
import com.alrex.parcool.common.entity.ParcoolEntityType;
import com.alrex.parcool.common.handlers.AddAttributesHandler;
import com.alrex.parcool.common.item.Items;
import com.alrex.parcool.common.item.recipe.Recipes;
import com.alrex.parcool.common.potion.PotionRecipeRegistry;
import com.alrex.parcool.common.potion.Potions;
import com.alrex.parcool.common.registries.EventBusForgeRegistry;
import com.alrex.parcool.compatibility.ServerEventWrapper;
import com.alrex.parcool.config.ParCoolConfig;
import com.alrex.parcool.extern.AdditionalMods;
import com.alrex.parcool.proxy.ClientProxy;
Expand Down Expand Up @@ -77,13 +78,13 @@ public ParCool() {

MinecraftForge.EVENT_BUS.addListener(this::registerCommand);
MinecraftForge.EVENT_BUS.register(this);
MinecraftForge.EVENT_BUS.addListener(Limitations::init);
MinecraftForge.EVENT_BUS.addListener(Limitations::save);
MinecraftForge.EVENT_BUS.addListener((event) -> Limitations.init(new ServerEventWrapper(event)));
MinecraftForge.EVENT_BUS.addListener((event) -> Limitations.save(new ServerEventWrapper(event)));

Blocks.register(FMLJavaModLoadingContext.get().getModEventBus());
Items.register(FMLJavaModLoadingContext.get().getModEventBus());
Recipes.register(FMLJavaModLoadingContext.get().getModEventBus());
EntityType.register(FMLJavaModLoadingContext.get().getModEventBus());
ParcoolEntityType.register(FMLJavaModLoadingContext.get().getModEventBus());
TileEntities.register(FMLJavaModLoadingContext.get().getModEventBus());

ModLoadingContext.get().registerConfig(ModConfig.Type.SERVER, ParCoolConfig.Server.BUILT_CONFIG);
Expand Down
9 changes: 4 additions & 5 deletions src/main/java/com/alrex/parcool/api/Stamina.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
package com.alrex.parcool.api;

import com.alrex.parcool.common.capability.IStamina;
import net.minecraft.entity.player.PlayerEntity;
import com.alrex.parcool.compatibility.PlayerWrapper;

import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;

import javax.annotation.Nullable;

public class Stamina {
@Nullable
public static Stamina get(PlayerEntity player) {
public static Stamina get(PlayerWrapper player) {
IStamina instance = IStamina.get(player);
if (instance == null) {
return null;
}
if (instance == null) return null;
return new Stamina(instance);
}

Expand Down
48 changes: 13 additions & 35 deletions src/main/java/com/alrex/parcool/api/unstable/Limitation.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,24 @@

import com.alrex.parcool.ParCool;
import com.alrex.parcool.common.action.Action;
import com.alrex.parcool.compatibility.MinecraftServerWrapper;
import com.alrex.parcool.compatibility.ServerPlayerWrapper;
import com.alrex.parcool.config.ParCoolConfig;
import com.alrex.parcool.server.limitation.Limitations;
import com.google.gson.stream.JsonWriter;
import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.server.MinecraftServer;

import java.io.BufferedOutputStream;
import com.alrex.parcool.utilities.JsonWriterUtil;
import java.io.File;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;

public abstract class Limitation {
public static Limitation get(ServerPlayerEntity player, ID limitationID) {
public static Limitation get(ServerPlayerWrapper player, ID limitationID) {
return new NormalLimitation(player, Limitations.createLimitationOf(player.getUUID(), limitationID.convert()));
}

public static Limitation getIndividual(ServerPlayerEntity player) {
public static Limitation getIndividual(ServerPlayerWrapper player) {
return new NormalLimitation(player, Limitations.createLimitationOf(player.getUUID(), Limitations.INDIVIDUAL_ID));
}

public static Limitation getGlobal(MinecraftServer server) {
public static Limitation getGlobal(MinecraftServerWrapper server) {
return new GlobalLimitation(server);
}

Expand Down Expand Up @@ -131,12 +124,12 @@ public static boolean delete(ID limitationID) {

private static class NormalLimitation extends Limitation {

private NormalLimitation(ServerPlayerEntity player, com.alrex.parcool.server.limitation.Limitation instance) {
private NormalLimitation(ServerPlayerWrapper player, com.alrex.parcool.server.limitation.Limitation instance) {
super(instance);
this.player = player;
}

private final ServerPlayerEntity player;
private final ServerPlayerWrapper player;

@Override
public void apply() {
Expand All @@ -162,37 +155,22 @@ public void save() {
if (!limitationFile.getParentFile().exists()) {
limitationFile.getParentFile().mkdirs();
}
try (JsonWriter writer =
new JsonWriter(
new OutputStreamWriter(
new BufferedOutputStream(
Files.newOutputStream(limitationFile.toPath(), StandardOpenOption.CREATE, StandardOpenOption.WRITE)
),
StandardCharsets.UTF_8
)
)
) {
instance.saveTo(writer);
} catch (IOException e) {
ParCool.LOGGER.error(
"IOException during saving limitation : "
+ e.getMessage()
);
}

JsonWriterUtil.Save(instance, limitationFile);
}
}

private static class GlobalLimitation extends Limitation {
private final MinecraftServer server;
private final MinecraftServerWrapper server;

private GlobalLimitation(MinecraftServer server) {
private GlobalLimitation(MinecraftServerWrapper server) {
super(Limitations.getGlobalLimitation());
this.server = server;
}

@Override
public void apply() {
for (ServerPlayerEntity player : server.getPlayerList().getPlayers()) {
for (ServerPlayerWrapper player : server.getServerPlayers()) {
Limitations.updateOnlyLimitation(player);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
package com.alrex.parcool.api.unstable.action;

import com.alrex.parcool.common.action.Action;
import net.minecraft.entity.player.PlayerEntity;
import com.alrex.parcool.compatibility.PlayerWrapper;

import net.minecraftforge.eventbus.api.Cancelable;
import net.minecraftforge.eventbus.api.Event;

public class ParCoolActionEvent extends Event {
private final PlayerEntity player;
private final PlayerWrapper player;
private final Action action;

public PlayerEntity getPlayer() {
public PlayerWrapper getPlayer() {
return player;
}

public Action getAction() {
return action;
}

public ParCoolActionEvent(PlayerEntity player, Action action) {
public ParCoolActionEvent(PlayerWrapper player, Action action) {
this.player = player;
this.action = action;
}
Expand All @@ -30,7 +31,7 @@ public boolean isCancelable() {
return true;
}

public TryToStartEvent(PlayerEntity player, Action action) {
public TryToStartEvent(PlayerWrapper player, Action action) {
super(player, action);
}
}
Expand All @@ -43,19 +44,19 @@ public boolean isCancelable() {
return true;
}

public TryToContinueEvent(PlayerEntity player, Action action) {
public TryToContinueEvent(PlayerWrapper player, Action action) {
super(player, action);
}
}

public static class StartEvent extends ParCoolActionEvent {
public StartEvent(PlayerEntity player, Action action) {
public StartEvent(PlayerWrapper player, Action action) {
super(player, action);
}
}

public static class StopEvent extends ParCoolActionEvent {
public StopEvent(PlayerEntity player, Action action) {
public StopEvent(PlayerWrapper player, Action action) {
super(player, action);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
package com.alrex.parcool.api.unstable.animation;

import com.alrex.parcool.client.animation.Animator;
import net.minecraft.client.entity.player.AbstractClientPlayerEntity;
import com.alrex.parcool.compatibility.AbstractClientPlayerWrapper;

import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.eventbus.api.Event;

@OnlyIn(Dist.CLIENT)
public class ParCoolAnimationInfoEvent extends Event {
private final AbstractClientPlayerEntity player;
private final AbstractClientPlayerWrapper player;
private final Animator animator;
private final AnimationOption option;

public ParCoolAnimationInfoEvent(
AbstractClientPlayerEntity player,
AbstractClientPlayerWrapper player,
Animator animator
) {
this.animator = animator;
this.player = player;
option = new AnimationOption();
}

public AbstractClientPlayerEntity getPlayer() {
public AbstractClientPlayerWrapper getPlayer() {
return player;
}

Expand Down
19 changes: 10 additions & 9 deletions src/main/java/com/alrex/parcool/client/animation/Animator.java
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
package com.alrex.parcool.client.animation;

import com.alrex.parcool.common.capability.Parkourability;
import net.minecraft.entity.player.PlayerEntity;
import com.alrex.parcool.compatibility.PlayerWrapper;

import net.minecraftforge.client.event.EntityViewRenderEvent;
import net.minecraftforge.event.TickEvent;

public abstract class Animator {
private int tick = 0;

public void tick(PlayerEntity player) {
public void tick(PlayerWrapper player) {
tick++;
}

protected int getTick() {
return tick;
}

public abstract boolean shouldRemoved(PlayerEntity player, Parkourability parkourability);
public abstract boolean shouldRemoved(PlayerWrapper player, Parkourability parkourability);

/**
* @return You should return true if you want to cancel vanilla animation to control all about rendering
*/
public boolean animatePre(
PlayerEntity player,
PlayerWrapper player,
Parkourability parkourability,
PlayerModelTransformer transformer
) {
Expand All @@ -34,37 +35,37 @@ public boolean animatePre(
* You can utilize this to use partially vanilla animation
*/
public void animatePost(
PlayerEntity player,
PlayerWrapper player,
Parkourability parkourability,
PlayerModelTransformer transformer
) {
}

public boolean rotatePre(
PlayerEntity player,
PlayerWrapper player,
Parkourability parkourability,
PlayerModelRotator rotator
) {
return false;
}

public void rotatePost(
PlayerEntity player,
PlayerWrapper player,
Parkourability parkourability,
PlayerModelRotator rotator
) {
}

public void onCameraSetUp(
EntityViewRenderEvent.CameraSetup event,
PlayerEntity clientPlayer,
PlayerWrapper clientPlayer,
Parkourability parkourability
) {
}

public void onRenderTick(
TickEvent.RenderTickEvent event,
PlayerEntity player,
PlayerWrapper player,
Parkourability parkourability
) {
}
Expand Down
Loading