-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Devan-Kerman
committed
Apr 9, 2020
1 parent
a8cb2e7
commit 73134b7
Showing
14 changed files
with
865 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,4 +23,8 @@ | |
hs_err_pid* | ||
|
||
# testing directory | ||
test | ||
test/.gradle | ||
test/build | ||
test/.idea | ||
test/run | ||
*.iml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import net.minecraft.block.Block; | ||
import net.minecraft.block.BlockState; | ||
import net.minecraft.block.entity.BlockEntity; | ||
import net.minecraft.network.packet.s2c.play.BlockUpdateS2CPacket; | ||
import net.minecraft.server.network.ServerPlayerEntity; | ||
import net.minecraft.server.network.ServerPlayerInteractionManager; | ||
import net.minecraft.server.world.ServerWorld; | ||
import net.minecraft.util.math.BlockPos; | ||
import net.minecraft.world.World; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
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.CallbackInfoReturnable; | ||
import org.spongepowered.asm.mixin.injection.callback.LocalCapture; | ||
|
||
/** | ||
* This is free and unencumbered software released into the public domain. | ||
* | ||
* Anyone is free to copy, modify, publish, use, compile, sell, or | ||
* distribute this software, either in source code form or as a compiled | ||
* binary, for any purpose, commercial or non-commercial, and by any | ||
* means. | ||
* | ||
* In jurisdictions that recognize copyright laws, the author or authors | ||
* of this software dedicate any and all copyright interest in the | ||
* software to the public domain. We make this dedication for the benefit | ||
* of the public at large and to the detriment of our heirs and | ||
* successors. We intend this dedication to be an overt act of | ||
* relinquishment in perpetuity of all present and future rights to this | ||
* software under copyright law. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
* IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR | ||
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, | ||
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR | ||
* OTHER DEALINGS IN THE SOFTWARE. | ||
* | ||
* For more information, please refer to <http://unlicense.org/> | ||
*/ | ||
@Mixin (ServerPlayerInteractionManager.class) | ||
public class PlayerBreakBlock { | ||
@Shadow public ServerPlayerEntity player; | ||
|
||
@Shadow public ServerWorld world; | ||
|
||
@Inject (method = "tryBreakBlock", | ||
at = @At (value = "INVOKE", | ||
target = "Lnet/minecraft/block/Block;onBreak(Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;Lnet/minecraft/entity/player/PlayerEntity;)V"), | ||
locals = LocalCapture.CAPTURE_FAILHARD, | ||
cancellable = true) | ||
private void breakBlock(BlockPos pos, CallbackInfoReturnable<Boolean> cir, BlockState state, BlockEntity entity, Block block) { | ||
if (!this.canBreakBlock(pos, state, entity, block)) { | ||
BlockPos cornerPos = pos.add(-1, -1, -1); | ||
for (int x = 0; x < 3; x++) { | ||
for (int y = 0; y < 3; y++) { | ||
for (int z = 0; z < 3; z++) { | ||
this.sendUpdate(this.world, cornerPos.add(x, y, z)); | ||
} | ||
} | ||
} | ||
cir.setReturnValue(false); | ||
} | ||
} | ||
|
||
private void sendUpdate(World world, BlockPos pos) { | ||
this.player.networkHandler.sendPacket(new BlockUpdateS2CPacket(world, pos)); | ||
} | ||
|
||
public boolean canBreakBlock(BlockPos pos, BlockState state, /*May be null*/ BlockEntity entity, Block block) { | ||
// replace with real logic | ||
System.out.println("Breaking"); | ||
return (pos.getY() & 1) != 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
import it.unimi.dsi.fastutil.ints.Int2ObjectMap; | ||
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; | ||
import net.fabricmc.fabric.api.event.server.ServerTickCallback; | ||
import net.minecraft.server.MinecraftServer; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.function.Consumer; | ||
import java.util.function.IntPredicate; | ||
|
||
/** | ||
* This is free and unencumbered software released into the public domain. | ||
* | ||
* Anyone is free to copy, modify, publish, use, compile, sell, or | ||
* distribute this software, either in source code form or as a compiled | ||
* binary, for any purpose, commercial or non-commercial, and by any | ||
* means. | ||
* | ||
* In jurisdictions that recognize copyright laws, the author or authors | ||
* of this software dedicate any and all copyright interest in the | ||
* software to the public domain. We make this dedication for the benefit | ||
* of the public at large and to the detriment of our heirs and | ||
* successors. We intend this dedication to be an overt act of | ||
* relinquishment in perpetuity of all present and future rights to this | ||
* software under copyright law. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
* IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR | ||
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, | ||
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR | ||
* OTHER DEALINGS IN THE SOFTWARE. | ||
* | ||
* For more information, please refer to <http://unlicense.org/> | ||
*/ | ||
public class Scheduler { | ||
private final Int2ObjectMap<List<Consumer<MinecraftServer>>> taskQueue = new Int2ObjectOpenHashMap<>(); | ||
private int currentTick = 0; | ||
|
||
public Scheduler() { | ||
ServerTickCallback.EVENT.register(m -> { | ||
this.currentTick = m.getTicks(); | ||
List<Consumer<MinecraftServer>> runnables = this.taskQueue.remove(this.currentTick); | ||
if (runnables != null) for (int i = 0; i < runnables.size(); i++) { | ||
Consumer<MinecraftServer> runnable = runnables.get(i); | ||
runnable.accept(m); | ||
|
||
if(runnable instanceof Repeating) {// reschedule repeating tasks | ||
Repeating repeating = ((Repeating) runnable); | ||
if(repeating.shouldQueue(this.currentTick)) | ||
this.queue(runnable, ((Repeating) runnable).next); | ||
} | ||
} | ||
|
||
}); | ||
} | ||
|
||
/** | ||
* queue a one time task to be executed on the server thread | ||
* @param tick how many ticks in the future this should be called, where 0 means at the end of the current tick | ||
* @param task the action to perform | ||
*/ | ||
public void queue(Consumer<MinecraftServer> task, int tick) { | ||
this.taskQueue.computeIfAbsent(this.currentTick + tick + 1, t -> new ArrayList<>()).add(task); | ||
} | ||
|
||
/** | ||
* schedule a repeating task that is executed infinitely every n ticks | ||
* @param task the action to perform | ||
* @param tick how many ticks in the future this event should first be called | ||
* @param interval the number of ticks in between each execution | ||
*/ | ||
public void repeating(Consumer<MinecraftServer> task, int tick, int interval) { | ||
this.repeatWhile(task, null, tick, interval); | ||
} | ||
|
||
/** | ||
* repeat the given task until the predicate returns false | ||
* @param task the action to perform | ||
* @param requeue whether or not to reschedule the task again, with the parameter being the current tick | ||
* @param tick how many ticks in the future this event should first be called | ||
* @param interval the number of ticks in between each execution | ||
*/ | ||
public void repeatWhile(Consumer<MinecraftServer> task, IntPredicate requeue, int tick, int interval) { | ||
this.queue(new Repeating(task, requeue, interval), tick); | ||
} | ||
|
||
/** | ||
* repeat the given task n times more than 1 time | ||
* @param task the action to perform | ||
* @param times the number of <b>additional</b> times the task should be scheduled | ||
* @param tick how many ticks in the future this event should first be called | ||
* * @param interval the number of ticks in between each execution | ||
*/ | ||
public void repeatN(Consumer<MinecraftServer> task, int times, int tick, int interval) { | ||
this.repeatWhile(task, new IntPredicate() { | ||
private int remaining = times; | ||
@Override | ||
public boolean test(int value) { | ||
return this.remaining-- > 0; | ||
} | ||
}, tick, interval); | ||
} | ||
|
||
private static final class Repeating implements Consumer<MinecraftServer> { | ||
private final Consumer<MinecraftServer> task; | ||
private final IntPredicate requeue; | ||
public final int next; | ||
|
||
private Repeating(Consumer<MinecraftServer> task, IntPredicate requeue, int interval) { | ||
this.task = task; | ||
this.requeue = requeue; | ||
this.next = interval; | ||
} | ||
|
||
public boolean shouldQueue(int predicate) { | ||
if(this.requeue == null) | ||
return true; | ||
return this.requeue.test(predicate); | ||
} | ||
|
||
|
||
@Override | ||
public void accept(MinecraftServer server) { | ||
this.task.accept(server); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
plugins { | ||
id 'fabric-loom' version '0.2.6-SNAPSHOT' | ||
id 'maven-publish' | ||
} | ||
|
||
sourceCompatibility = JavaVersion.VERSION_1_8 | ||
targetCompatibility = JavaVersion.VERSION_1_8 | ||
|
||
archivesBaseName = project.archives_base_name | ||
version = project.mod_version | ||
group = project.maven_group | ||
|
||
minecraft { | ||
} | ||
|
||
dependencies { | ||
minecraft "com.mojang:minecraft:${project.minecraft_version}" | ||
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2" | ||
modCompile "net.fabricmc:fabric-loader:${project.loader_version}" | ||
|
||
modCompile "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" | ||
} | ||
|
||
processResources { | ||
inputs.property "version", project.version | ||
|
||
from(sourceSets.main.resources.srcDirs) { | ||
include "fabric.mod.json" | ||
expand "version": project.version | ||
} | ||
|
||
from(sourceSets.main.resources.srcDirs) { | ||
exclude "fabric.mod.json" | ||
} | ||
} | ||
|
||
// ensure that the encoding is set to UTF-8, no matter what the system default is | ||
// this fixes some edge cases with special characters not displaying correctly | ||
// see http://yodaconditions.net/blog/fix-for-java-file-encoding-problems-with-gradle.html | ||
tasks.withType(JavaCompile) { | ||
options.encoding = "UTF-8" | ||
} | ||
|
||
// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task | ||
// if it is present. | ||
// If you remove this task, sources will not be generated. | ||
task sourcesJar(type: Jar, dependsOn: classes) { | ||
classifier = "sources" | ||
from sourceSets.main.allSource | ||
} | ||
|
||
jar { | ||
from "LICENSE" | ||
} | ||
|
||
// configure the maven publication | ||
publishing { | ||
publications { | ||
mavenJava(MavenPublication) { | ||
// add all the jars that should be included when publishing to maven | ||
artifact(remapJar) { | ||
builtBy remapJar | ||
} | ||
artifact(sourcesJar) { | ||
builtBy remapSourcesJar | ||
} | ||
} | ||
} | ||
|
||
// select the repositories you want to publish to | ||
repositories { | ||
// uncomment to publish to the local maven | ||
// mavenLocal() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Done to increase the memory available to gradle. | ||
org.gradle.jvmargs=-Xmx1G | ||
# Fabric Properties | ||
# check these on https://fabricmc.net/use | ||
minecraft_version=1.15.2 | ||
yarn_mappings=1.15.2+build.15 | ||
loader_version=0.8.2+build.194 | ||
# Mod Properties | ||
mod_version=1.0-SNAPSHOT | ||
maven_group=net.devtech | ||
archives_base_name=onemixin | ||
# Dependencies | ||
# currently not on the main fabric site, check on the maven: https://maven.fabricmc.net/net/fabricmc/fabric-api/fabric-api | ||
fabric_version=0.5.1+build.294-1.15 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-5.5.1-bin.zip | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists |
Oops, something went wrong.