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
1 parent
b0d1c97
commit 1a4f658
Showing
39 changed files
with
2,226 additions
and
797 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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,15 @@ | ||
* text eol=lf | ||
*.bat text eol=crlf | ||
*.patch text eol=lf | ||
*.java text eol=lf | ||
*.gradle text eol=crlf | ||
*.png binary | ||
*.gif binary | ||
*.exe binary | ||
*.dll binary | ||
*.jar binary | ||
*.lzma binary | ||
*.zip binary | ||
*.pyd binary | ||
*.cfg text eol=lf | ||
*.jks binary |
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 |
---|---|---|
@@ -1,30 +1,26 @@ | ||
*.class | ||
|
||
# Package Files # | ||
*.war | ||
*.ear | ||
/build | ||
/eclipse | ||
/bin | ||
/out | ||
# eclipse | ||
bin | ||
*.launch | ||
.settings | ||
.metadata | ||
.classpath | ||
.project | ||
|
||
*.mtl | ||
*.classpath | ||
*.project | ||
/.gradle | ||
/.settings | ||
/.idea | ||
*.iml | ||
# idea | ||
out | ||
*.ipr | ||
*.iws | ||
/.metadata/* | ||
*.eml | ||
/run/ | ||
usernamecache.json | ||
*.stackdump | ||
*.launch | ||
secrets.json | ||
*.iml | ||
.idea | ||
|
||
changelog.md | ||
# gradle | ||
build | ||
.gradle | ||
|
||
# other | ||
eclipse | ||
run | ||
secrets.json | ||
changelog.md | ||
*.launch | ||
logs/ |
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,38 @@ | ||
buildscript { | ||
repositories { | ||
maven { | ||
name = "BlameJared" | ||
url = 'https://maven.blamejared.com' | ||
} | ||
maven { url = 'https://repo.spongepowered.org/repository/maven-public/' } | ||
} | ||
dependencies { | ||
classpath group: 'com.blamejared', name: 'ModTemplate', version: '2.+', changing: true | ||
} | ||
} | ||
plugins { | ||
id("java") | ||
id("org.spongepowered.gradle.vanilla") version "0.2" | ||
} | ||
apply plugin: 'com.blamejared.modtemplate' | ||
import com.blamejared.modtemplate.Utils | ||
|
||
archivesBaseName = "${mod_name}-common-${minecraft_version}" | ||
version = Utils.updatingVersion(mod_version) | ||
group = mod_group | ||
|
||
repositories { | ||
mavenCentral() | ||
maven { url = 'https://repo.spongepowered.org/repository/maven-public/' } | ||
} | ||
|
||
minecraft { | ||
version(minecraft_version) // or: latestRelease() or latestSnapshot() | ||
runs { | ||
server() | ||
client() | ||
} | ||
} | ||
dependencies { | ||
implementation "org.spongepowered:mixin:0.8.4" | ||
} |
11 changes: 11 additions & 0 deletions
11
Common/src/main/java/com/blamejared/clumps/ClumpsCommon.java
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,11 @@ | ||
package com.blamejared.clumps; | ||
|
||
|
||
import com.blamejared.clumps.helper.IOrbHelper; | ||
import com.blamejared.clumps.stub.StubOrbHelper; | ||
|
||
public class ClumpsCommon { | ||
|
||
public static IOrbHelper orbHelper = new StubOrbHelper(); | ||
|
||
} |
11 changes: 11 additions & 0 deletions
11
Common/src/main/java/com/blamejared/clumps/helper/IClumpedOrb.java
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,11 @@ | ||
package com.blamejared.clumps.helper; | ||
|
||
import java.util.Map; | ||
|
||
public interface IClumpedOrb { | ||
|
||
public Map<Integer, Integer> clumps$getClumpedMap(); | ||
|
||
public void clumps$setClumpedMap(Map<Integer, Integer> map); | ||
|
||
} |
25 changes: 25 additions & 0 deletions
25
Common/src/main/java/com/blamejared/clumps/helper/IOrbHelper.java
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,25 @@ | ||
package com.blamejared.clumps.helper; | ||
|
||
import net.minecraft.world.entity.ExperienceOrb; | ||
import net.minecraft.world.entity.player.Player; | ||
|
||
public interface IOrbHelper { | ||
|
||
void setCount(ExperienceOrb orb, int count); | ||
|
||
void setAge(ExperienceOrb orb, int age); | ||
|
||
int getCount(ExperienceOrb orb); | ||
|
||
int getValue(ExperienceOrb orb); | ||
|
||
int getAge(ExperienceOrb orb); | ||
|
||
int repairPlayerItems(ExperienceOrb orb, Player param0, int param1); | ||
|
||
default boolean fireXPPickup(Player player, ExperienceOrb orb) { | ||
|
||
return false; | ||
} | ||
|
||
} |
129 changes: 129 additions & 0 deletions
129
Common/src/main/java/com/blamejared/clumps/stub/StubExperienceOrb.java
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,129 @@ | ||
package com.blamejared.clumps.stub; | ||
|
||
import com.blamejared.clumps.ClumpsCommon; | ||
import com.blamejared.clumps.helper.IClumpedOrb; | ||
import net.minecraft.nbt.CompoundTag; | ||
import net.minecraft.server.level.ServerLevel; | ||
import net.minecraft.world.entity.ExperienceOrb; | ||
import net.minecraft.world.entity.player.Player; | ||
import net.minecraft.world.level.entity.EntityTypeTest; | ||
import net.minecraft.world.phys.AABB; | ||
import net.minecraft.world.phys.Vec3; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; | ||
|
||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
|
||
// The actual mixin needs to be done in each project, so it can actually be recognized and have a refmap generated. | ||
// I put very minimal effort into actually getting it to work, the issue is that MixinGradle requires ForgeGradle, | ||
// so it isn't easy to just make it use the common sourceset. | ||
// If anyone knows how to get around this, please let me know. | ||
|
||
// So lets just make a stub to hold the logic. | ||
public class StubExperienceOrb { | ||
|
||
public static void canMerge(ExperienceOrb thisOrb, ExperienceOrb experienceOrb, CallbackInfoReturnable<Boolean> cir) { | ||
|
||
cir.setReturnValue(experienceOrb.isAlive() && !thisOrb.is(experienceOrb)); | ||
} | ||
|
||
private static boolean canMerge(ExperienceOrb experienceOrb, int i, int j) { | ||
|
||
return experienceOrb.isAlive(); | ||
} | ||
|
||
public static void canMerge(ExperienceOrb experienceOrb, int i, int j, CallbackInfoReturnable<Boolean> cir) { | ||
|
||
cir.setReturnValue(canMerge(experienceOrb, i, j)); | ||
} | ||
|
||
public static void playerTouch(ExperienceOrb thisOrb, Player player, CallbackInfo ci) { | ||
|
||
if(!thisOrb.level.isClientSide) { | ||
// Fire the Forge event | ||
if(ClumpsCommon.orbHelper.fireXPPickup(player, thisOrb)) { | ||
return; | ||
} | ||
player.takeXpDelay = 0; | ||
player.take(thisOrb, 1); | ||
|
||
((IClumpedOrb) thisOrb).clumps$getClumpedMap().forEach((value, amount) -> { | ||
for(int i = 0; i < amount; i++) { | ||
int leftOver = ClumpsCommon.orbHelper.repairPlayerItems(thisOrb, player, value); | ||
if(leftOver > 0) { | ||
player.giveExperiencePoints(leftOver); | ||
} | ||
} | ||
}); | ||
|
||
thisOrb.discard(); | ||
ci.cancel(); | ||
} | ||
|
||
} | ||
|
||
public static void merge(ExperienceOrb thisOrb, ExperienceOrb secondaryOrb, CallbackInfo ci) { | ||
|
||
Map<Integer, Integer> otherMap = ((IClumpedOrb) secondaryOrb).clumps$getClumpedMap(); | ||
((IClumpedOrb) thisOrb).clumps$setClumpedMap(Stream.of(((IClumpedOrb) thisOrb).clumps$getClumpedMap(), otherMap) | ||
.flatMap(map -> map.entrySet().stream()) | ||
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, Integer::sum))); | ||
ClumpsCommon.orbHelper.setCount(thisOrb, ((IClumpedOrb) thisOrb).clumps$getClumpedMap() | ||
.values() | ||
.stream() | ||
.reduce(Integer::sum) | ||
.orElse(1)); | ||
ClumpsCommon.orbHelper.setAge(thisOrb, Math.min(ClumpsCommon.orbHelper.getAge(thisOrb), ClumpsCommon.orbHelper.getAge(secondaryOrb))); | ||
secondaryOrb.discard(); | ||
ci.cancel(); | ||
} | ||
|
||
public static void tryMergeToExisting(ServerLevel serverLevel, Vec3 vec3, int i, CallbackInfoReturnable<Boolean> cir) { | ||
|
||
AABB aABB = AABB.ofSize(vec3, 1.0D, 1.0D, 1.0D); | ||
int j = serverLevel.getRandom().nextInt(40); | ||
List<ExperienceOrb> list = serverLevel.getEntities(EntityTypeTest.forClass(ExperienceOrb.class), aABB, (experienceOrbx) -> canMerge(experienceOrbx, j, i)); | ||
if(!list.isEmpty()) { | ||
ExperienceOrb experienceOrb = list.get(0); | ||
Map<Integer, Integer> clumpedMap = ((IClumpedOrb) experienceOrb).clumps$getClumpedMap(); | ||
clumpedMap = Stream.of(clumpedMap, Collections.singletonMap(i, 1)) | ||
.flatMap(map -> map.entrySet().stream()) | ||
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, Integer::sum)); | ||
((IClumpedOrb) experienceOrb).clumps$setClumpedMap(clumpedMap); | ||
ClumpsCommon.orbHelper.setCount(experienceOrb, clumpedMap.values().stream().reduce(Integer::sum).orElse(1)); | ||
ClumpsCommon.orbHelper.setAge(experienceOrb, 0); | ||
cir.setReturnValue(true); | ||
} else { | ||
cir.setReturnValue(false); | ||
} | ||
} | ||
|
||
public static void addAdditionalSaveData(ExperienceOrb thisOrb, CompoundTag compoundTag, CallbackInfo ci) { | ||
|
||
CompoundTag map = new CompoundTag(); | ||
((IClumpedOrb) thisOrb).clumps$getClumpedMap().forEach((value, count) -> map.putInt(value + "", count)); | ||
compoundTag.put("clumpedMap", map); | ||
} | ||
|
||
public static void readAdditionalSaveData(ExperienceOrb thisOrb, CompoundTag compoundTag, CallbackInfo ci) { | ||
|
||
Map<Integer, Integer> map = new HashMap<>(); | ||
if(compoundTag.contains("clumpedMap")) { | ||
CompoundTag clumpedMap = compoundTag.getCompound("clumpedMap"); | ||
for(String s : clumpedMap.getAllKeys()) { | ||
map.put(Integer.parseInt(s), clumpedMap.getInt(s)); | ||
} | ||
} else { | ||
map.put(ClumpsCommon.orbHelper.getValue(thisOrb), ClumpsCommon.orbHelper.getCount(thisOrb)); | ||
} | ||
|
||
((IClumpedOrb) thisOrb).clumps$setClumpedMap(map); | ||
} | ||
|
||
|
||
} |
45 changes: 45 additions & 0 deletions
45
Common/src/main/java/com/blamejared/clumps/stub/StubOrbHelper.java
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,45 @@ | ||
package com.blamejared.clumps.stub; | ||
|
||
import com.blamejared.clumps.helper.IOrbHelper; | ||
import net.minecraft.world.entity.ExperienceOrb; | ||
import net.minecraft.world.entity.player.Player; | ||
|
||
public class StubOrbHelper implements IOrbHelper { | ||
|
||
@Override | ||
public void setCount(ExperienceOrb orb, int count) { | ||
|
||
throw new IllegalArgumentException("ClumpsCommon.orbHelper was not set! This should never happen!"); | ||
} | ||
|
||
@Override | ||
public void setAge(ExperienceOrb orb, int age) { | ||
|
||
throw new IllegalArgumentException("ClumpsCommon.orbHelper was not set! This should never happen!"); | ||
} | ||
|
||
@Override | ||
public int getCount(ExperienceOrb orb) { | ||
|
||
throw new IllegalArgumentException("ClumpsCommon.orbHelper was not set! This should never happen!"); | ||
} | ||
|
||
@Override | ||
public int getValue(ExperienceOrb orb) { | ||
|
||
throw new IllegalArgumentException("ClumpsCommon.orbHelper was not set! This should never happen!"); | ||
} | ||
|
||
@Override | ||
public int getAge(ExperienceOrb orb) { | ||
|
||
throw new IllegalArgumentException("ClumpsCommon.orbHelper was not set! This should never happen!"); | ||
} | ||
|
||
@Override | ||
public int repairPlayerItems(ExperienceOrb orb, Player player, int param1) { | ||
|
||
throw new IllegalArgumentException("ClumpsCommon.orbHelper was not set! This should never happen!"); | ||
} | ||
|
||
} |
Oops, something went wrong.