Merge branch 'master' into light

# Conflicts:
#	src/main/resources/carpet.accesswidener
#	src/main/resources/fabric.mod.json
This commit is contained in:
gnembon committed 2020-07-01 00:11:35 -03:00
commit 7067e59a21
66 files changed
+1898 -495

No files matched your search

@@ -14,6 +14,11 @@ public class ClientPlayerEntity_clientCommandMixin
@Inject(method = "sendChatMessage", at = @At("HEAD"))
private void inspectMessage(String string, CallbackInfo ci)
{
if (string.startsWith("/call"))
{
String command = string.substring(6);
CarpetClient.sendClientCommand(command);
}
if (CarpetServer.minecraft_server == null && !CarpetClient.isCarpet())
{
ClientPlayerEntity playerSource = (ClientPlayerEntity)(Object) this;
@@ -0,0 +1,26 @@
package carpet.mixins;
import carpet.fakes.IngredientInterface;
import net.minecraft.item.ItemStack;
import net.minecraft.recipe.Ingredient;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;
@Mixin(Ingredient.class)
public class Ingredient_scarpetMixin implements IngredientInterface
{
@Shadow @Final private Ingredient.Entry[] entries;
@Override
public List<Collection<ItemStack>> getRecipeStacks()
{
List<Collection<ItemStack>> res = Arrays.stream(entries).map(Ingredient.Entry::getStacks).collect(Collectors.toList());
return res;
}
}
@@ -31,13 +31,18 @@ public abstract class MinecraftServer_coreMixin
CarpetServer.tick((MinecraftServer) (Object) this);
}
// Dedicated server only
@Inject(method = "loadWorld", at = @At("HEAD"))
private void serverLoaded(String string_1, String string_2, long long_1, LevelGeneratorType levelGeneratorType_1, JsonElement jsonElement_1, CallbackInfo ci)
{
CarpetServer.onServerLoaded((MinecraftServer) (Object) this);
}
@Inject(method = "loadWorld", at = @At("RETURN"))
private void serverLoadedWorlds(String string_1, String string_2, long long_1, LevelGeneratorType levelGeneratorType_1, JsonElement jsonElement_1, CallbackInfo ci)
{
CarpetServer.onServerLoadedWorlds((MinecraftServer) (Object) this);
}
@Inject(method = "shutdown", at = @At("HEAD"))
private void serverClosed(CallbackInfo ci)
{
@@ -39,7 +39,7 @@ public abstract class MinecraftServer_scarpetMixin extends ReentrantThreadExecut
{
timeReference = field_4557 = Util.getMeasuringTimeMs();
tick(isAhead);
runTask();
while(runTask()) {Thread.yield();}
}
@Inject(method = "tick", at = @At(
@@ -4,6 +4,7 @@ import carpet.helpers.TickSpeed;
import carpet.utils.CarpetProfiler;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.ServerTask;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.Util;
import net.minecraft.util.profiler.DisableableProfiler;
import net.minecraft.util.thread.ReentrantThreadExecutor;
@@ -50,6 +51,8 @@ public abstract class MinecraftServer_tickspeedMixin extends ReentrantThreadExec
@Shadow private volatile boolean loading;
@Shadow public abstract Iterable<ServerWorld> getWorlds();
CarpetProfiler.ProfilerToken currentSection;
private float carpetMsptAccum = 0.0f;
@@ -120,16 +123,16 @@ public abstract class MinecraftServer_tickspeedMixin extends ReentrantThreadExec
this.profiler.startTick();
this.profiler.push("tick");
this.tick(TickSpeed.time_warp_start_time != 0 ? ()->!hasRunningTasks() : this::shouldKeepTicking);
this.tick(TickSpeed.time_warp_start_time != 0 ? ()->true : this::shouldKeepTicking);
this.profiler.swap("nextTickWait");
if (TickSpeed.time_warp_start_time != 0) // clearing all hanging tasks no matter what when warping
{
while(this.runEveryTask()) {Thread.yield();}
}
this.field_19249 = true;
this.field_19248 = Math.max(Util.getMeasuringTimeMs() + /*50L*/ msThisTick, this.timeReference);
if (TickSpeed.time_warp_start_time != 0)
{
runTasks();
runTasks(() -> !hasRunningTasks() );
}
else { this.method_16208(); }
// run all tasks (this will not do a lot when warping), but that's fine since we already run them
this.method_16208();
this.profiler.pop();
this.profiler.endTick();
this.loading = true;
@@ -137,6 +140,23 @@ public abstract class MinecraftServer_tickspeedMixin extends ReentrantThreadExec
}
private boolean runEveryTask() {
if (super.runTask()) {
return true;
} else {
if (true) { // unconditionally this time
for(ServerWorld serverlevel : getWorlds()) {
if (serverlevel.getChunkManager().executeQueuedTasks()) {
return true;
}
}
}
return false;
}
}
@Inject(method = "tick", at = @At(
value = "INVOKE",
target = "Lnet/minecraft/server/PlayerManager;saveAllPlayerData()V",
@@ -16,6 +16,7 @@ public abstract class MobEntityMixin implements MobEntityInterface
{
@Shadow @Final protected GoalSelector targetSelector;
@Shadow @Final protected GoalSelector goalSelector;
@Shadow private boolean persistent;
public final Map<String, Goal> temporaryTasks = new HashMap<>();
@Override
@@ -30,5 +31,9 @@ public abstract class MobEntityMixin implements MobEntityInterface
return temporaryTasks;
}
@Override
public void setPersistence(boolean what)
{
persistent = what;
}
}
@@ -0,0 +1,32 @@
package carpet.mixins;
import carpet.fakes.RecipeManagerInterface;
import com.google.common.collect.Lists;
import net.minecraft.recipe.Recipe;
import net.minecraft.recipe.RecipeManager;
import net.minecraft.recipe.RecipeType;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@Mixin(RecipeManager.class)
public class RecipeManager_scarpetMixin implements RecipeManagerInterface
{
@Shadow private Map<RecipeType<?>, Map<Identifier, Recipe<?>>> recipes;
@Override
public List<Recipe<?>> getAllMatching(RecipeType type, Identifier output)
{
Map<Identifier, Recipe<?>> typeRecipes = recipes.get(type);
if (typeRecipes.containsKey(output)) return Collections.singletonList(typeRecipes.get(output));
return Lists.newArrayList(typeRecipes.values().stream().filter(
r -> Registry.ITEM.getId(r.getOutput().getItem()).equals(output)).collect(Collectors.toList()));
}
}
@@ -1,6 +1,9 @@
package carpet.mixins;
import net.minecraft.item.ItemStack;
import net.minecraft.network.packet.c2s.play.ButtonClickC2SPacket;
import net.minecraft.network.packet.c2s.play.CraftRequestC2SPacket;
import net.minecraft.network.packet.c2s.play.UpdateSelectedSlotC2SPacket;
import net.minecraft.server.network.ServerPlayNetworkHandler;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.network.packet.c2s.play.ClientCommandC2SPacket;
@@ -29,10 +32,12 @@ import static carpet.script.CarpetEventServer.Event.PLAYER_RELEASED_ITEM;
import static carpet.script.CarpetEventServer.Event.PLAYER_RIDES;
import static carpet.script.CarpetEventServer.Event.PLAYER_JUMPS;
import static carpet.script.CarpetEventServer.Event.PLAYER_RIGHT_CLICKS_BLOCK;
import static carpet.script.CarpetEventServer.Event.PLAYER_CHOOSES_RECIPE;
import static carpet.script.CarpetEventServer.Event.PLAYER_STARTS_SNEAKING;
import static carpet.script.CarpetEventServer.Event.PLAYER_STARTS_SPRINTING;
import static carpet.script.CarpetEventServer.Event.PLAYER_STOPS_SNEAKING;
import static carpet.script.CarpetEventServer.Event.PLAYER_STOPS_SPRINTING;
import static carpet.script.CarpetEventServer.Event.PLAYER_SWITCHES_SLOT;
import static carpet.script.CarpetEventServer.Event.PLAYER_USES_ITEM;
import static carpet.script.CarpetEventServer.Event.PLAYER_WAKES_UP;
@@ -219,4 +224,28 @@ public class ServerPlayNetworkHandler_scarpetEventsMixin
//todo add hit and hand in the future
PLAYER_ATTACKS_ENTITY.onEntityAction(player, playerInteractEntityC2SPacket_1.getEntity(player.getServerWorld()), null);
}
@Inject(method = "onButtonClick", at = @At("HEAD"))
private void onItemBeingPickedFromInventory(ButtonClickC2SPacket packet, CallbackInfo ci)
{
// crafts not int the crafting window
//CarpetSettings.LOG.error("Player clicks button "+packet.getButtonId());
}
@Inject(method = "onCraftRequest", at = @At("HEAD"))
private void onRecipeSelectedInRecipeManager(CraftRequestC2SPacket packet, CallbackInfo ci)
{
if (PLAYER_CHOOSES_RECIPE.isNeeded())
{
PLAYER_CHOOSES_RECIPE.onRecipeSelected(player, packet.getRecipe(), packet.shouldCraftAll());
}
}
@Inject(method = "onUpdateSelectedSlot", at = @At("HEAD"))
private void onUpdatedSelectedSLot(UpdateSelectedSlotC2SPacket packet, CallbackInfo ci)
{
if (PLAYER_SWITCHES_SLOT.isNeeded())
{
PLAYER_SWITCHES_SLOT.onSlotSwitch(player, player.inventory.selectedSlot, packet.getSelectedSlot());
}
}
}