maven { url 'https://files.minecraftforge.net/maven' }
}
dependencies {
- classpath 'com.github.Irtimaled:ForgeGradle:' + project.mcVersion + '-SNAPSHOT'
+ classpath 'net.minecraftforge.gradle:ForgeGradle:2.3-SNAPSHOT'
classpath 'org.spongepowered:mixingradle:0.6-SNAPSHOT'
}
}
minecraft {
version = project.mcVersion
- mappings = 'snapshot_20180908'
+ mappings = 'snapshot_20171003'
runDir = 'run'
tweakClass = 'com.irtimaled.bbor.launch.ClientTweaker'
makeObfSourceJar = false
name=bbor
buildVersion=1.0.13
# leave a space to reduce merge conflicts on version change
-mcVersion=1.13
+mcVersion=1.12.2
package com.irtimaled.bbor;
import com.irtimaled.bbor.install.Installer;
-import com.irtimaled.bbor.server.ServerRunner;
-
-import java.io.IOException;
-import java.util.Arrays;
public class Main {
- public static void main(String... args) throws IOException {
- if (args.length > 0 && args[0].equals("--server")) {
- ServerRunner.run("@MC_VERSION@", Arrays.asList(args).subList(1, args.length));
- } else {
- Installer.install("@VERSION@", "@MC_VERSION@");
-
- }
+ public static void main(String... args) {
+ Installer.install("@VERSION@", "@MC_VERSION@");
}
}
public static boolean active;
static {
- KeyListener.register("Toggle Active", 0x42, Name)
+ KeyListener.register("Toggle Active", 0x30, Name)
.onKeyPressHandler(ClientProxy::toggleActive)
.onLongKeyPressHandler(60, SettingsScreen::show);
- KeyListener.register("Toggle Outer Box Only", 0x4f, Name)
+ KeyListener.register("Toggle Outer Box Only", 0x18, Name)
.onKeyPressHandler(ClientProxy::toggleOuterBoxesOnly);
}
EventBus.subscribe(SeedCommandTyped.class, this::onSeedCommandTyped);
renderer = new ClientRenderer(this::getCache);
- KeyListener.init();
}
private void render(Render event) {
}
private int getRenderDistanceChunks() {
- return Minecraft.getInstance().gameSettings.renderDistanceChunks;
+ return Minecraft.getMinecraft().gameSettings.renderDistanceChunks;
}
private boolean isSlimeChunk(int chunkX, int chunkZ) {
@Override
public void render(int mouseX, int mouseY) {
- super.render(mouseX, mouseY, 0f);
+ super.drawButton(Minecraft.getMinecraft(), mouseX, mouseY, 0f);
}
@Override
- protected void renderBg(Minecraft p_renderBg_1_, int p_renderBg_2_, int p_renderBg_3_) {
+ protected void mouseDragged(Minecraft mc, int mouseX, int mouseY) {
renderBackground();
}
}
@Override
- public void onClick(double mouseX, double mouseY) {
- super.onClick(mouseX, mouseY);
- onPressed();
+ public boolean mousePressed(Minecraft mc, int mouseX, int mouseY) {
+ if (super.mousePressed(mc, mouseX, mouseY)) {
+ onPressed();
+ return true;
+ }
+ return false;
}
protected abstract void onPressed();
abstract class AbstractSlider extends GuiButton implements IRenderableControl {
double progress;
+ private boolean dragging = false;
AbstractSlider(int id, int x, int y, int width) {
super(id, x, y, width, 20, "");
@Override
public void render(int mouseX, int mouseY) {
- super.render(mouseX, mouseY, 0f);
+ super.drawButton(Minecraft.getMinecraft(), mouseX, mouseY, 0f);
}
@Override
- protected void renderBg(Minecraft minecraft, int mouseX, int mouseY) {
+ protected void mouseDragged(Minecraft minecraft, int mouseX, int mouseY) {
+ if (dragging) {
+ changeProgress(mouseX);
+ }
minecraft.getTextureManager().bindTexture(BUTTON_TEXTURES);
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
this.drawTexturedModalRect(this.x + (int) (this.progress * (double) (this.width - 8)), this.y, 0, 66, 4, 20);
return 0;
}
+
@Override
- protected void onDrag(double mouseX, double mouseY, double deltaX, double deltaY) {
- changeProgress(mouseX);
- super.onDrag(mouseX, mouseY, deltaX, deltaY);
+ public boolean mousePressed(Minecraft mc, int mouseX, int mouseY) {
+ if (super.mousePressed(mc, mouseX, mouseY)) {
+ changeProgress(mouseX);
+ dragging = true;
+ return true;
+ }
+ return false;
}
@Override
- public void onClick(double mouseX, double mouseY) {
- changeProgress(mouseX);
- super.onClick(mouseX, mouseY);
+ public void mouseReleased(int mouseX, int mouseY) {
+ dragging = false;
}
protected abstract void updateText();
import com.irtimaled.bbor.config.ConfigManager;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Gui;
+import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
-import net.minecraft.client.gui.IGuiEventListener;
import net.minecraft.client.renderer.OpenGlHelper;
import org.lwjgl.opengl.GL11;
}
public static void show() {
- Minecraft.getInstance().displayGuiScreen(new SettingsScreen(null, 0));
+ Minecraft.getMinecraft().displayGuiScreen(new SettingsScreen(null, 0));
}
private int getY(double row) {
private void addControl(IRenderableControl control) {
this.controls.add(control);
- TypeHelper.doIfType(control, IGuiEventListener.class, this.eventListeners::add);
+ TypeHelper.doIfType(control, GuiButton.class, this.buttonList::add);
}
private void addTabs(String... labels) {
(id, x, y1, width) -> new AbstractButton(id, x, y, width, label, index != tabIndex) {
@Override
public void onPressed() {
- Minecraft.getInstance().displayGuiScreen(new SettingsScreen(lastScreen, index));
+ Minecraft.getMinecraft().displayGuiScreen(new SettingsScreen(lastScreen, index));
}
});
column++;
}
@Override
- protected void initGui() {
+ public void initGui() {
this.title = ClientProxy.Name;
this.controls = new HashSet<>();
(id, x, y, width) -> new BoundingBoxTypeButton(id, x, y, width, "Monuments", BoundingBoxType.OceanMonument),
(id, x, y, width) -> new BoundingBoxTypeButton(id, x, y, width, "Igloos", BoundingBoxType.Igloo),
- (id, x, y, width) -> new BoundingBoxTypeButton(id, x, y, width, "Ocean Ruins", BoundingBoxType.OceanRuin),
- (id, x, y, width) -> new BoundingBoxTypeButton(id, x, y, width, "Buried Treasure", BoundingBoxType.BuriedTreasure),
- (id, x, y, width) -> new BoundingBoxTypeButton(id, x, y, width, "Shipwrecks", BoundingBoxType.Shipwreck),
+ (id, x, y, width) -> new BoundingBoxTypeButton(id, x, y, width, "Ocean Ruins", BoundingBoxType.OceanRuin, false),
+ (id, x, y, width) -> new BoundingBoxTypeButton(id, x, y, width, "Buried Treasure", BoundingBoxType.BuriedTreasure, false),
+ (id, x, y, width) -> new BoundingBoxTypeButton(id, x, y, width, "Shipwrecks", BoundingBoxType.Shipwreck, false),
(id, x, y, width) -> new BoundingBoxTypeButton(id, x, y, width, "Pillager Outposts", BoundingBoxType.PillagerOutpost, false),
(id, x, y, width) -> new BoundingBoxTypeButton(id, x, y, width, "Strongholds", BoundingBoxType.Stronghold),
.render();
GL11.glDisable(GL11.GL_DEPTH_TEST);
- GL11.glEnable(GL11.GL_BLEND);
- OpenGlHelper.glBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ZERO, GL11.GL_ONE);
+ OpenGlHelper.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ZERO, GL11.GL_ONE);
GL11.glDisable(GL11.GL_ALPHA_TEST);
GL11.glShadeModel(7425);
GL11.glEnable(GL11.GL_TEXTURE_2D);
GL11.glShadeModel(7424);
GL11.glEnable(GL11.GL_ALPHA_TEST);
- OpenGlHelper.glBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ZERO);
+ OpenGlHelper.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ZERO);
GL11.glDisable(GL11.GL_BLEND);
}
@Override
- public void render(int mouseX, int mouseY, float unknown) {
+ public void drawScreen(int mouseX, int mouseY, float partialTicks) {
if (this.mc.world == null) {
this.drawDefaultBackground();
this.drawScreen(getY(-1), getY(5.5) - 4);
@Override
public void onPressed() {
- Minecraft.getInstance().displayGuiScreen(screen);
+ Minecraft.getMinecraft().displayGuiScreen(screen);
}
}
package com.irtimaled.bbor.client.keyboard;
import net.minecraft.client.settings.KeyBinding;
-import net.minecraft.client.util.InputMappings;
public class Key extends KeyBinding {
- private InputMappings.Input input;
private KeyHandler onKeyPress;
private KeyHandler onLongKeyPress;
private int longPressDuration;
return this;
}
- InputMappings.Input getInput() {
- if (input == null)
- return getDefault();
- return input;
- }
-
- @Override
- public void bind(InputMappings.Input input) {
- this.input = input;
- super.bind(input);
- }
-
private int pressDuration = 0;
@Override
public boolean isPressed() {
- return pressDuration == 1;
+ return pressDuration >= 1;
}
void release() {
if (pressDuration == longPressDuration) {
onLongKeyPress.handle();
+ pressDuration = 0;
}
}
package com.irtimaled.bbor.client.keyboard;
-import net.minecraft.client.Minecraft;
import net.minecraft.client.settings.KeyBinding;
-import net.minecraft.client.util.InputMappings;
-import org.lwjgl.glfw.GLFW;
import java.util.HashSet;
import java.util.Set;
public class KeyListener {
- private static final Minecraft minecraft = Minecraft.getInstance();
- private static long mainWindowHandle;
private static Set<Key> keys = new HashSet<>();
- public static void init() {
- mainWindowHandle = minecraft.mainWindow.getHandle();
- GLFW.glfwSetKeyCallback(mainWindowHandle, KeyListener::onKeyEvent);
- }
-
public static Key register(String description, int keyCode, String category) {
Key key = new Key(description, keyCode, category);
keys.add(key);
return key;
}
- private static void onKeyEvent(long windowHandle, int keyCode, int scanCode, int action, int modifiers) {
- if (windowHandle == mainWindowHandle && minecraft.currentScreen == null && keyCode != -1 && !InputMappings.isKeyDown(292)) {
- InputMappings.Input input = InputMappings.getInputByCode(keyCode, scanCode);
- for (Key key : keys) {
- if (key.getInput() == input) {
- switch (action) {
- case GLFW.GLFW_PRESS:
- key.press();
- break;
- case GLFW.GLFW_REPEAT:
- key.repeat();
- break;
- case GLFW.GLFW_RELEASE:
- key.release();
- return;
- }
- if (minecraft.currentScreen != null)
- key.release();
- return;
+ public static KeyBinding[] keyBindings() {
+ return keys.toArray(new KeyBinding[0]);
+ }
+
+ public static boolean setKeyBindState(int keyCode, boolean pressed) {
+ for (Key key : keys) {
+ if (key.getKeyCode() == keyCode) {
+ if (!pressed) {
+ key.release();
+ } else if (key.isPressed()) {
+ key.repeat();
+ } else {
+ key.press();
}
+ return true;
}
}
- minecraft.keyboardListener.onKeyEvent(windowHandle, keyCode, scanCode, action, modifiers);
- }
-
- public static KeyBinding[] keyBindings() {
- return keys.stream().toArray(KeyBinding[]::new);
+ return false;
}
}
import com.irtimaled.bbor.common.models.Coords;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityMobSpawner;
-import net.minecraft.util.math.MutableBoundingBox;
+import net.minecraft.util.math.ChunkPos;
import net.minecraft.world.chunk.Chunk;
-import net.minecraft.world.gen.feature.structure.StructurePiece;
-import net.minecraft.world.gen.feature.structure.StructureStart;
+import net.minecraft.world.chunk.IChunkProvider;
+import net.minecraft.world.gen.ChunkProviderServer;
+import net.minecraft.world.gen.IChunkGenerator;
+import net.minecraft.world.gen.structure.MapGenStructure;
+import net.minecraft.world.gen.structure.StructureBoundingBox;
+import net.minecraft.world.gen.structure.StructureComponent;
+import net.minecraft.world.gen.structure.StructureStart;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
+import java.util.*;
+import java.util.function.Function;
public abstract class AbstractChunkProcessor {
- Set<BoundingBoxType> supportedStructures = new HashSet<>();
+ Map<BoundingBoxType, Function<IChunkGenerator, Collection<StructureStart>>> supportedStructures = new HashMap<>();
AbstractChunkProcessor(BoundingBoxCache boundingBoxCache) {
this.boundingBoxCache = boundingBoxCache;
private final BoundingBoxCache boundingBoxCache;
- private void addStructures(BoundingBoxType type, Map<String, StructureStart> structureMap) {
- StructureStart structureStart = structureMap.get(type.getName());
- if (structureStart == null) return;
+ static <T extends IChunkGenerator, R extends MapGenStructure> Collection<StructureStart> getStructures(T chunkGenerator, Class<R> generatorClass) {
+ Class<T> chunkGeneratorClass = (Class<T>) chunkGenerator.getClass();
+ R structureGenerator = ReflectionHelper.getPrivateValue(chunkGeneratorClass, chunkGenerator, generatorClass);
+ if (structureGenerator != null) {
+ Map<ChunkPos, StructureStart> structureMap = ReflectionHelper.getPrivateValue(MapGenStructure.class, structureGenerator, Map.class);
+ return structureMap.values();
+ }
+ return Collections.emptyList();
+ }
+
+ Collection<StructureStart> getStructuresWithComponent(Collection<StructureStart> structures, Class structureComponent) {
+ Collection<StructureStart> validStructures = new HashSet<>();
+ for (StructureStart structure : structures) {
+ if (structure.getComponents().get(0).getClass().equals(structureComponent)) {
+ validStructures.add(structure);
+ }
+ }
+ return validStructures;
+ }
- MutableBoundingBox bb = structureStart.getBoundingBox();
+
+ private void addStructures(BoundingBoxType type, StructureStart structureStart) {
+ StructureBoundingBox bb = structureStart.getBoundingBox();
if (bb == null) return;
AbstractBoundingBox boundingBox = buildStructure(bb, type);
if (boundingBoxCache.isCached(boundingBox)) return;
Set<AbstractBoundingBox> structureBoundingBoxes = new HashSet<>();
- for (StructurePiece structureComponent : structureStart.getComponents()) {
+ for (StructureComponent structureComponent : structureStart.getComponents()) {
structureBoundingBoxes.add(buildStructure(structureComponent.getBoundingBox(), type));
}
boundingBoxCache.addBoundingBoxes(boundingBox, structureBoundingBoxes);
}
- private AbstractBoundingBox buildStructure(MutableBoundingBox bb, BoundingBoxType type) {
+ private AbstractBoundingBox buildStructure(StructureBoundingBox bb, BoundingBoxType type) {
Coords min = new Coords(bb.minX, bb.minY, bb.minZ);
Coords max = new Coords(bb.maxX, bb.maxY, bb.maxZ);
return BoundingBoxStructure.from(min, max, type);
}
private void addMobSpawners(Chunk chunk) {
- Collection<TileEntity> tileEntities = chunk.getTileEntityMap().values();
+ Collection<TileEntity> tileEntities = chunk.getWorld().loadedTileEntityList;
for (TileEntity tileEntity : tileEntities) {
TileEntityMobSpawner spawner = TypeHelper.as(tileEntity, TileEntityMobSpawner.class);
if (spawner != null) {
}
public void process(Chunk chunk) {
- Map<String, StructureStart> structureMap = chunk.getStructureStarts();
- if (structureMap.size() > 0) {
- supportedStructures.forEach(type -> addStructures(type, structureMap));
- }
+ IChunkProvider chunkProvider = chunk.getWorld().getChunkProvider();
+ IChunkGenerator chunkGenerator = ReflectionHelper.getPrivateValue(ChunkProviderServer.class, (ChunkProviderServer) chunkProvider, IChunkGenerator.class);
+ supportedStructures.forEach((type, supplier) ->
+ {
+ Collection<StructureStart> structureStarts = supplier.apply(chunkGenerator);
+ structureStarts.forEach(structureStart -> addStructures(type, structureStart));
+ }
+ );
addMobSpawners(chunk);
}
}
import com.irtimaled.bbor.common.BoundingBoxCache;
import com.irtimaled.bbor.common.BoundingBoxType;
+import net.minecraft.world.gen.structure.MapGenEndCity;
public class EndChunkProcessor extends AbstractChunkProcessor {
public EndChunkProcessor(BoundingBoxCache boundingBoxCache) {
super(boundingBoxCache);
- supportedStructures.add(BoundingBoxType.EndCity);
+ supportedStructures.put(BoundingBoxType.EndCity, (chunkGenerator) -> getStructures(chunkGenerator, MapGenEndCity.class));
}
}
import com.irtimaled.bbor.common.BoundingBoxCache;
import com.irtimaled.bbor.common.BoundingBoxType;
+import net.minecraft.world.gen.structure.MapGenNetherBridge;
public class NetherChunkProcessor extends AbstractChunkProcessor {
public NetherChunkProcessor(BoundingBoxCache boundingBoxCache) {
super(boundingBoxCache);
- supportedStructures.add(BoundingBoxType.NetherFortress);
+ supportedStructures.put(BoundingBoxType.NetherFortress, (chunkGenerator) -> getStructures(chunkGenerator, MapGenNetherBridge.class));
}
}
import com.irtimaled.bbor.common.BoundingBoxCache;
import com.irtimaled.bbor.common.BoundingBoxType;
+import net.minecraft.world.gen.structure.*;
public class OverworldChunkProcessor extends AbstractChunkProcessor {
public OverworldChunkProcessor(BoundingBoxCache boundingBoxCache) {
super(boundingBoxCache);
- supportedStructures.add(BoundingBoxType.DesertTemple);
- supportedStructures.add(BoundingBoxType.JungleTemple);
- supportedStructures.add(BoundingBoxType.WitchHut);
- supportedStructures.add(BoundingBoxType.OceanMonument);
- supportedStructures.add(BoundingBoxType.Stronghold);
- supportedStructures.add(BoundingBoxType.Mansion);
- supportedStructures.add(BoundingBoxType.MineShaft);
- supportedStructures.add(BoundingBoxType.Shipwreck);
- supportedStructures.add(BoundingBoxType.OceanRuin);
- supportedStructures.add(BoundingBoxType.BuriedTreasure);
- supportedStructures.add(BoundingBoxType.Igloo);
- supportedStructures.add(BoundingBoxType.PillagerOutpost);
+ supportedStructures.put(BoundingBoxType.DesertTemple, (chunkGenerator) -> getStructuresWithComponent(getStructures(chunkGenerator, MapGenScatteredFeature.class), ComponentScatteredFeaturePieces.DesertPyramid.class));
+ supportedStructures.put(BoundingBoxType.JungleTemple, (chunkGenerator) -> getStructuresWithComponent(getStructures(chunkGenerator, MapGenScatteredFeature.class), ComponentScatteredFeaturePieces.JunglePyramid.class));
+ supportedStructures.put(BoundingBoxType.WitchHut, (chunkGenerator) -> getStructuresWithComponent(getStructures(chunkGenerator, MapGenScatteredFeature.class), ComponentScatteredFeaturePieces.SwampHut.class));
+ supportedStructures.put(BoundingBoxType.OceanMonument, (chunkGenerator) -> getStructures(chunkGenerator, StructureOceanMonument.class));
+ supportedStructures.put(BoundingBoxType.Stronghold, (chunkGenerator) -> getStructures(chunkGenerator, MapGenStronghold.class));
+ supportedStructures.put(BoundingBoxType.Mansion, (chunkGenerator) -> getStructures(chunkGenerator, WoodlandMansion.class));
+ supportedStructures.put(BoundingBoxType.MineShaft, (chunkGenerator) -> getStructures(chunkGenerator, MapGenMineshaft.class));
+ supportedStructures.put(BoundingBoxType.Igloo, (chunkGenerator) -> getStructuresWithComponent(getStructures(chunkGenerator, MapGenScatteredFeature.class), ComponentScatteredFeaturePieces.Igloo.class));
}
}
--- /dev/null
+package com.irtimaled.bbor.common.chunkProcessors;
+
+import java.lang.reflect.Field;
+import java.util.HashMap;
+import java.util.Map;
+
+public class ReflectionHelper {
+ public static <T, R> R getPrivateValue(Class<T> sourceClass, T instance, Class<R> resultClass) {
+ try {
+ Field f = getField(sourceClass, resultClass);
+ if (f != null) {
+ return (R) f.get(instance);
+ }
+ } catch (Exception ignored) {
+ }
+ return null;
+ }
+
+ private static Map<Class, Map<Class, Field>> fieldMap = new HashMap<>();
+
+ private static <T, R> Field getField(Class<T> sourceClass, Class<R> resultClass) {
+ Map<Class, Field> map = fieldMap.computeIfAbsent(sourceClass, k -> new HashMap<>());
+ Field field = map.get(resultClass);
+ if (field == null) {
+ field = getFieldUsingReflection(sourceClass, resultClass);
+ if (field != null) {
+ field.setAccessible(true);
+ map.put(resultClass, field);
+ }
+ }
+ return field;
+ }
+
+ private static <T, R> Field getFieldUsingReflection(Class<T> sourceClass, Class<R> resultClass) {
+ Field[] fields = sourceClass.getDeclaredFields();
+ for (Field field : fields) {
+ if (field.getType().equals(resultClass))
+ return field;
+ }
+ for (Field field : fields) {
+ if (resultClass.isAssignableFrom(field.getType()))
+ return field;
+ }
+ return null;
+ }
+}
\ No newline at end of file
public ChunkLoaded(Chunk chunk) {
this.chunk = chunk;
- this.dimensionId = chunk.getWorld().getDimension().getType().getId();
+ this.dimensionId = chunk.getWorld().provider.getDimensionType().getId();
}
public Chunk getChunk() {
public ServerWorldTick(WorldServer world) {
this.world = world;
- this.dimensionId = world.getDimension().getType().getId();
+ this.dimensionId = world.provider.getDimensionType().getId();
}
public WorldServer getWorld() {
public WorldLoaded(WorldServer world) {
WorldInfo info = world.getWorldInfo();
- this.dimensionId = world.getDimension().getType().getId();
+ this.dimensionId = world.provider.getDimensionType().getId();
this.seed = info.getSeed();
this.spawnX = info.getSpawnX();
this.spawnZ = info.getSpawnZ();
public static void tryHarvestBlock(Block block, BlockPos pos, World world) {
if (block instanceof BlockMobSpawner) {
- EventBus.publish(new MobSpawnerBroken(world.dimension.getType().getId(), new Coords(pos)));
+ EventBus.publish(new MobSpawnerBroken(world.provider.getDimensionType().getId(), new Coords(pos)));
}
}
}
import java.util.Set;
public class AddBoundingBox {
- public static final String NAME = "bbor:add_bounding_box";
+ public static final String NAME = "bbor:addbb";
public static PayloadBuilder getPayload(int dimensionId, AbstractBoundingBox key, Set<AbstractBoundingBox> boundingBoxes) {
if (!BoundingBoxSerializer.canSerialize(key)) return null;
import com.irtimaled.bbor.client.events.InitializeClientReceived;
public class InitializeClient {
- public static final String NAME = "bbor:initialize";
+ public static final String NAME = "bbor:init";
public static PayloadBuilder getPayload(long seed, int spawnX, int spawnZ) {
return PayloadBuilder.clientBound(NAME)
import net.minecraft.network.PacketBuffer;
import net.minecraft.network.play.client.CPacketCustomPayload;
import net.minecraft.network.play.server.SPacketCustomPayload;
-import net.minecraft.util.ResourceLocation;
-import java.util.HashMap;
-import java.util.Map;
import java.util.function.BiFunction;
public class PayloadBuilder {
- private static Map<String, ResourceLocation> packetNames = new HashMap<>();
-
static PayloadBuilder clientBound(String name) {
- return new PayloadBuilder(packetNames.computeIfAbsent(name, ResourceLocation::new), SPacketCustomPayload::new);
+ return new PayloadBuilder(name, SPacketCustomPayload::new);
}
static PayloadBuilder serverBound(String name) {
- return new PayloadBuilder(packetNames.computeIfAbsent(name, ResourceLocation::new), CPacketCustomPayload::new);
+ return new PayloadBuilder(name, CPacketCustomPayload::new);
}
- private final ResourceLocation name;
- private final BiFunction<ResourceLocation, PacketBuffer, Packet<?>> packetBuilder;
+ private final String name;
+ private final BiFunction<String, PacketBuffer, Packet<?>> packetBuilder;
private final PacketBuffer buffer;
- private PayloadBuilder(ResourceLocation name, BiFunction<ResourceLocation, PacketBuffer, Packet<?>> packetBuilder) {
+ private PayloadBuilder(String name, BiFunction<String, PacketBuffer, Packet<?>> packetBuilder) {
this.name = name;
this.buffer = new PacketBuffer(Unpooled.buffer());
this.packetBuilder = packetBuilder;
import com.irtimaled.bbor.common.models.AbstractBoundingBox;
public class RemoveBoundingBox {
- public static final String NAME = "bbor:remove_bounding_box";
+ public static final String NAME = "bbor:removebb";
public static PayloadBuilder getPayload(int dimensionId, AbstractBoundingBox key) {
if (!BoundingBoxSerializer.canSerialize(key)) return null;
package com.irtimaled.bbor.common.messages;
public class SubscribeToServer {
- public static final String NAME = "bbor:subscribe";
+ public static final String NAME = "bbor:sub";
public static PayloadBuilder getPayload() {
return PayloadBuilder.serverBound(NAME);
package com.irtimaled.bbor.mixin.client;
import com.irtimaled.bbor.client.ClientProxy;
+import com.irtimaled.bbor.client.keyboard.KeyListener;
import com.irtimaled.bbor.common.interop.CommonInterop;
import net.minecraft.client.Minecraft;
import net.minecraft.client.main.GameConfiguration;
+import net.minecraft.client.settings.KeyBinding;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
+import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(Minecraft.class)
private void init(CallbackInfo ci) {
clientProxy.init();
}
+
+ @Redirect(method = "runTickKeyboard", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/settings/KeyBinding;setKeyBindState(IZ)V"))
+ private void setKeyBindState(int keyCode, boolean pressed) {
+ if (!KeyListener.setKeyBindState(keyCode, pressed)) {
+ KeyBinding.setKeyBindState(keyCode, pressed);
+ }
+ }
}
//shuffle middle buttons up by 12 px to make space
int top = this.height / 6 + 42;
int bottom = this.height / 6 + 168;
- for (GuiButton button : buttons) {
+ for (GuiButton button : buttonList) {
if (button.y >= top && button.y < bottom)
button.y -= 12;
}
@Final
private Minecraft mc;
- @Inject(method = "updateCameraAndRender(FJ)V", at = @At(value = "INVOKE_STRING", target = "Lnet/minecraft/profiler/Profiler;endStartSection(Ljava/lang/String;)V", args = "ldc=hand", shift = At.Shift.BEFORE))
- private void render(float partialTicks, long ignored, CallbackInfo ci) {
- ClientInterop.render(partialTicks, this.mc.player);
+ @Inject(method = "renderWorldPass", at = @At(value = "INVOKE_STRING", target = "Lnet/minecraft/profiler/Profiler;endStartSection(Ljava/lang/String;)V", args = "ldc=hand", shift = At.Shift.BEFORE))
+ private void render(int pass, float partialTicks, long finishTimeNano, CallbackInfo ci) {
+ if (pass % 2 == 0) {
+ ClientInterop.render(partialTicks, this.mc.player);
+ }
}
}
package com.irtimaled.bbor.mixin.client.settings;
import com.irtimaled.bbor.client.keyboard.KeyListener;
-import net.minecraft.client.GameSettings;
import net.minecraft.client.Minecraft;
+import net.minecraft.client.settings.GameSettings;
import net.minecraft.client.settings.KeyBinding;
import org.apache.commons.lang3.ArrayUtils;
import org.spongepowered.asm.mixin.Mixin;
import net.minecraft.network.NetHandlerPlayServer;
import net.minecraft.network.play.INetHandlerPlayServer;
import net.minecraft.network.play.client.CPacketCustomPayload;
-import net.minecraft.util.ResourceLocation;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
@Mixin(CPacketCustomPayload.class)
public class MixinCPacketCustomPayload {
@Shadow
- private ResourceLocation channel;
+ private String channel;
@Redirect(method = "processPacket", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/play/INetHandlerPlayServer;processCustomPayload(Lnet/minecraft/network/play/client/CPacketCustomPayload;)V"))
private void processPacket(INetHandlerPlayServer netHandlerPlayServer, CPacketCustomPayload packet) {
- if (this.channel.toString().equals(SubscribeToServer.NAME)) {
+ if (this.channel.equals(SubscribeToServer.NAME)) {
CommonInterop.playerSubscribed(((NetHandlerPlayServer) netHandlerPlayServer).player);
} else {
netHandlerPlayServer.processCustomPayload(packet);
import net.minecraft.network.PacketBuffer;
import net.minecraft.network.play.INetHandlerPlayClient;
import net.minecraft.network.play.server.SPacketCustomPayload;
-import net.minecraft.util.ResourceLocation;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
@Mixin(SPacketCustomPayload.class)
public abstract class MixinSPacketCustomPayload {
@Shadow
- private ResourceLocation channel;
+ private String channel;
@Redirect(method = "processPacket", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/play/INetHandlerPlayClient;handleCustomPayload(Lnet/minecraft/network/play/server/SPacketCustomPayload;)V"))
private void processPacket(INetHandlerPlayClient netHandlerPlayClient, SPacketCustomPayload packet) {
- String channelName = channel.toString();
- if (channelName.startsWith("bbor:")) {
+ if (this.channel.startsWith("bbor:")) {
PacketBuffer data = null;
try {
data = packet.getBufferData();
PayloadReader reader = new PayloadReader(data);
- switch (channelName) {
+ switch (this.channel) {
case InitializeClient.NAME: {
EventBus.publish(InitializeClient.getEvent(reader));
((NetHandlerPlayClient) netHandlerPlayClient).sendPacket(SubscribeToServer.getPayload().build());
+++ /dev/null
-package com.irtimaled.bbor.mixin.server.dedicated;
-
-import com.irtimaled.bbor.common.CommonProxy;
-import com.irtimaled.bbor.common.interop.CommonInterop;
-import net.minecraft.server.dedicated.DedicatedServer;
-import org.spongepowered.asm.mixin.Mixin;
-import org.spongepowered.asm.mixin.injection.At;
-import org.spongepowered.asm.mixin.injection.Inject;
-import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
-
-@Mixin(DedicatedServer.class)
-public class MixinDedicatedServer {
- @Inject(method = "init", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/dedicated/DedicatedServer;loadAllWorlds(Ljava/lang/String;Ljava/lang/String;JLnet/minecraft/world/WorldType;Lcom/google/gson/JsonElement;)V"))
- private void init(CallbackInfoReturnable<Boolean> cir) {
- CommonInterop.init();
- new CommonProxy().init();
- }
-}
+++ /dev/null
-package com.irtimaled.bbor.server;
-
-import net.minecraft.launchwrapper.Launch;
-
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.lang.reflect.Method;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.net.URLClassLoader;
-import java.nio.channels.Channels;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-public class ServerRunner {
- private static final Map<String, String> VANILLA_SERVER_JARS = new HashMap<>();
-
- private static final String[] LIBRARIES = {
- "https://github.com/irtimaled/Mixin/releases/download/org/spongepowered/mixin/0.7.11-SNAPSHOT/mixin-0.7.11-SNAPSHOT.jar",
- "https://repo1.maven.org/maven2/org/ow2/asm/asm/6.2/asm-6.2.jar",
- "https://repo1.maven.org/maven2/org/ow2/asm/asm-commons/6.2/asm-commons-6.2.jar",
- "https://repo1.maven.org/maven2/org/ow2/asm/asm-tree/6.2/asm-tree-6.2.jar",
- "https://libraries.minecraft.net/net/minecraft/launchwrapper/1.12/launchwrapper-1.12.jar"
- };
-
- private static final ThrowableConsumer<URL> addURL;
-
- static {
- VANILLA_SERVER_JARS.put("1.13", "https://launcher.mojang.com/v1/objects/d0caafb8438ebd206f99930cfaecfa6c9a13dca0/server.jar");
-
- try {
- Method method = URLClassLoader.class
- .getDeclaredMethod("addURL", URL.class);
- method.setAccessible(true);
- addURL = url -> method.invoke(ClassLoader.getSystemClassLoader(), url);
- } catch (ReflectiveOperationException e) {
- throw new AssertionError(e);
- }
- }
-
- private static void addURLToClasspath(File file) throws MalformedURLException {
- addURL.accept(file.toURI().toURL());
- }
-
- public static void run(String version, List<String> args) throws IOException {
- String serverJarUrl = VANILLA_SERVER_JARS.get(version);
-
- addURLToClasspath(getOrDownload(new File("."), serverJarUrl));
- for (String url : LIBRARIES) {
- addURLToClasspath(getOrDownload(new File("libs"), url));
- }
-
- args = new ArrayList<>(args);
- args.add("--tweakClass");
- args.add("com.irtimaled.bbor.launch.ServerTweaker");
-
- System.out.println("Launching server...");
- Launch.main(args.toArray(new String[0]));
- }
-
- private static File getOrDownload(File directory, String url) throws IOException {
- String fileName = url.substring(url.lastIndexOf('/') + 1);
- File target = new File(directory, fileName);
- if (target.isFile()) {
- return target;
- }
- target.getParentFile().mkdirs();
-
- System.out.println("Downloading library: " + url);
- new FileOutputStream(target).getChannel()
- .transferFrom(Channels.newChannel(new URL(url).openStream()), 0, Long.MAX_VALUE);
-
- return target;
- }
-}
+++ /dev/null
-package com.irtimaled.bbor.server;
-
-import com.irtimaled.bbor.common.TypeHelper;
-
-import java.util.function.Consumer;
-
-public interface ThrowableConsumer<T> extends Consumer<T> {
- @Override
- default void accept(final T elem) {
- try {
- acceptThrows(elem);
- } catch (final Throwable t) {
- throw TypeHelper.as(t, RuntimeException.class, () -> new RuntimeException(t));
- }
- }
-
- void acceptThrows(T elem) throws Throwable;
-}
"client.settings.MixinKeyBinding",
"network.play.server.MixinSPacketCustomPayload",
"network.play.server.MixinSPacketSpawnPosition"
- ],
- "server": [
- "server.dedicated.MixinDedicatedServer"
]
}