Skip to content

Commit 77426f0

Browse files
committed
A few features
- Added version checker - Added debuffs at various health thresholds and a buff on full health - Ghosts are invisible - Added temp debuff on filling a heart - White list blocks ghosts can interact with - White list blocks ghosts can break - White list items ghosts can pickup and use - More config options
1 parent a6da642 commit 77426f0

File tree

6 files changed

+201
-29
lines changed

6 files changed

+201
-29
lines changed

java/werty/softerhardcore/main/Config.java

+22-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
package werty.softerhardcore.main;
22

33
import java.io.File;
4+
import java.util.ArrayList;
5+
import java.util.List;
46

7+
import net.minecraft.block.Block;
58
import net.minecraftforge.common.config.Configuration;
69
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
710

@@ -14,19 +17,37 @@ public class Config
1417

1518
public static int damageBoost;
1619
public static int healthXP;
20+
public static int sicknessTicks;
1721

1822
public static boolean ghostMode;
23+
public static boolean checkForUpdates;
24+
public static boolean healthEffects;
25+
public static boolean fiilEffects;
26+
public static boolean ghostInvisibility;
27+
28+
public static String interactableBlocks;
29+
public static String breakableBlocks;
30+
public static String usableItems;
1931

2032
public static void configInit(FMLPreInitializationEvent event)
2133
{
2234
Configuration config = new Configuration(new File("config/SofterHardcore.cfg"));
2335
config.load();
2436
healthStarting = config.get("Mechanics", "StartingHealth", 20D, "Starting health. Vanilla is 20").getDouble();
2537
healthMax = config.get("Mechanics", "MaxHealth", 20D, "Max health. Vanilla is 20").getDouble();
38+
sicknessTicks = config.get("Mechanics", "SicknessTicks", 12000, "How long the sickness will last 12000 = 10 minutes").getInt();
2639
deathAmount = config.get("Mechanics", "DeathAmount", 2D, "Amount of healh taken on death").getDouble();
2740
damageBoost = config.get("Mechanics", "DamageBoost", 2, "Damage boost added to monsters").getInt();
2841
healthXP = config.get("Mechanics", "ExperienceForHeart", 10, "Experience level needed to fill a heart").getInt();
29-
ghostMode = config.get("Mechanics", "GhostMode", true, "If player will spawn with debuffs lasting 10 minutes").getBoolean();
42+
ghostMode = config.get("Mechanics", "GhostMode", true, "If player will spawn with debuffs").getBoolean();
43+
fiilEffects = config.get("Mechanics", "HeartFillEffects", true, "If player suffer temp. Debuff on filling up a heart").getBoolean();
44+
ghostInvisibility = config.get("Mechanics", "GhostInvisibility", true, "Gain Invisibility as a ghost").getBoolean();
45+
checkForUpdates = config.get("Mechanics", "CheckForUpdates", true, "Should mod check for updates?").getBoolean();
46+
healthEffects = config.get("Mechanics", "HealthEffects", true, "Debuffs on thresholds at 1/2 and 1/3 health and a damage boost at full health").getBoolean();
47+
48+
interactableBlocks = config.get("Ghost", "GhostInteractableBlocks", "modid:blockid", "Blocks ghost players can interact with using right click. Add blocks seperated with a , and using ModID:BlockID").getString();
49+
breakableBlocks = config.get("Ghost", "GhostBreakableBlocks", "modid:blockid", "Blocks ghost players can break with. Add blocks seperated with a , and using ModID:BlockID").getString();
50+
usableItems = config.get("Ghost", "GhostUsableItems", "modid:itemid", "Items ghost players can pick up and use. Add items seperated with a , and using ModID:itemID").getString();
3051
config.save();
3152
}
3253
}

java/werty/softerhardcore/main/ItemHeartEmpty.java

+8
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
import net.minecraft.entity.player.EntityPlayer;
55
import net.minecraft.item.Item;
66
import net.minecraft.item.ItemStack;
7+
import net.minecraft.potion.Potion;
8+
import net.minecraft.potion.PotionEffect;
9+
import net.minecraft.util.ChatComponentText;
710
import net.minecraft.world.World;
811

912
public class ItemHeartEmpty extends Item
@@ -25,6 +28,11 @@ public ItemStack onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPl
2528
{
2629
playerIn.experienceLevel -= Config.healthXP;
2730
--itemStackIn.stackSize;
31+
if(Config.fiilEffects)
32+
{
33+
playerIn.addChatMessage(new ChatComponentText("You feel weak after transfering energy to the crystal"));
34+
playerIn.addPotionEffect(new PotionEffect(Potion.weakness.id, Config.sicknessTicks, 0, false, false));
35+
}
2836
return new ItemStack(SHItems.heart_full);
2937
}
3038
}

java/werty/softerhardcore/main/References.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public class References
88
public static final String MODID = "softerhardcore";
99
public static final String ACRONYM = "SH";
1010
public static final String NAME = "Softer Hardcore";
11-
public static final String VERSION = "1.8.0-1.0.0";
11+
public static final String VERSION = "1.8.0-1.1.0";
1212

1313
public static final List<String> AUTHORS = Arrays.asList("TheWerty1124");
1414

java/werty/softerhardcore/main/SHEventHandler.java

+97-25
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
package werty.softerhardcore.main;
22

3+
import java.lang.reflect.Method;
34
import java.util.ArrayList;
45
import java.util.List;
56

67
import net.minecraft.block.Block;
78
import net.minecraft.entity.SharedMonsterAttributes;
89
import net.minecraft.entity.player.EntityPlayer;
910
import net.minecraft.init.Blocks;
10-
import net.minecraft.init.Items;
11+
import net.minecraft.item.Item;
1112
import net.minecraft.nbt.NBTTagCompound;
1213
import net.minecraft.potion.Potion;
1314
import net.minecraft.potion.PotionEffect;
@@ -17,17 +18,68 @@
1718
import net.minecraftforge.event.entity.living.LivingDeathEvent;
1819
import net.minecraftforge.event.entity.living.LivingEvent.LivingUpdateEvent;
1920
import net.minecraftforge.event.entity.living.LivingHurtEvent;
20-
import net.minecraftforge.event.entity.living.LivingSetAttackTargetEvent;
2121
import net.minecraftforge.event.entity.player.EntityItemPickupEvent;
2222
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
2323
import net.minecraftforge.event.entity.player.PlayerInteractEvent.Action;
24+
import net.minecraftforge.event.world.BlockEvent;
2425
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
26+
import net.minecraftforge.fml.common.registry.FMLControlledNamespacedRegistry;
27+
import net.minecraftforge.fml.common.registry.GameData;
28+
import net.minecraftforge.fml.common.registry.GameRegistry;
2529

2630
public class SHEventHandler
2731
{
32+
33+
private static List<Block> interactableBlocks = new ArrayList<Block>();
34+
private static List<Block> breakableBlocks = new ArrayList<Block>();
35+
36+
private static List<Item> usableItems = new ArrayList<Item>();
37+
38+
public static void loadAllowedBlocksandItems()
39+
{
40+
interactableBlocks.add(Blocks.acacia_door);
41+
interactableBlocks.add(Blocks.oak_door);
42+
interactableBlocks.add(Blocks.birch_door);
43+
interactableBlocks.add(Blocks.spruce_door);
44+
interactableBlocks.add(Blocks.dark_oak_door);
45+
interactableBlocks.add(Blocks.lever);
46+
interactableBlocks.add(Blocks.wooden_button);
47+
interactableBlocks.add(Blocks.stone_button);
48+
49+
for(String s : Config.interactableBlocks.split(","))
50+
{
51+
String[] blockID = s.split(":");
52+
if(blockID != null && blockID.length >= 1)
53+
{
54+
interactableBlocks.add(Block.getBlockFromItem(GameRegistry.findItem(blockID[0].trim(), blockID[1].trim())));
55+
}
56+
}
57+
58+
for(String s : Config.breakableBlocks.split(","))
59+
{
60+
String[] blockID = s.split(":");
61+
if(blockID != null && blockID.length >= 1)
62+
{
63+
breakableBlocks.add(Block.getBlockFromItem(GameRegistry.findItem(blockID[0].trim(), blockID[1].trim())));
64+
}
65+
}
66+
67+
usableItems.add(SHItems.heart_full);
68+
69+
for(String s : Config.usableItems.split(","))
70+
{
71+
String[] itemID = s.split(":");
72+
if(itemID != null && itemID.length >= 1)
73+
{
74+
usableItems.add(GameRegistry.findItem(itemID[0].trim(), itemID[1].trim()));
75+
}
76+
}
77+
}
78+
2879
@SubscribeEvent
2980
public void onPlayerJoin(EntityJoinWorldEvent event)
3081
{
82+
VersionChecker check = new VersionChecker(References.VERSION, "https://raw.githubusercontent.com/werty1124/SofterHardcore/master/version.txt", References.NAME);
3183
if (event.entity instanceof EntityPlayer)
3284
{
3385
EntityPlayer player = (EntityPlayer) event.entity;
@@ -39,6 +91,12 @@ public void onPlayerJoin(EntityJoinWorldEvent event)
3991
{
4092
event.entity.addChatMessage(new ChatComponentText("SofterHardcore is meant to be played in survival. It will NOT prevent the deletion of worlds!"));
4193
}
94+
if(Config.checkForUpdates && !SofterHardcore.hasCheckedVersion)
95+
{
96+
check.run();
97+
event.entity.addChatMessage(VersionChecker.uptoDate);
98+
SofterHardcore.hasCheckedVersion = true;
99+
}
42100
}
43101
if(nbt.hasKey("ghost") && nbt.getBoolean("ghost"))
44102
{
@@ -55,6 +113,7 @@ public void onPlayerJoin(EntityJoinWorldEvent event)
55113
player.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(nbt.getDouble("health"));
56114
}
57115
}
116+
58117
if(Config.ghostMode == false && player.getMaxHealth() <= 0)
59118
{
60119
addDebuffs(player);
@@ -66,10 +125,10 @@ public void onPlayerJoin(EntityJoinWorldEvent event)
66125

67126
public void addDebuffs(EntityPlayer player)
68127
{
69-
player.addPotionEffect(new PotionEffect(Potion.weakness.id, 12000, 0, false, false));
70-
player.addPotionEffect(new PotionEffect(Potion.digSlowdown.id, 12000, 0, false, false));
71-
player.addPotionEffect(new PotionEffect(Potion.blindness.id, 3000, 0, false, false));
72-
player.addPotionEffect(new PotionEffect(Potion.moveSlowdown.id, 12000, 0, false, false));
128+
player.addPotionEffect(new PotionEffect(Potion.weakness.id, Config.sicknessTicks, 0, false, false));
129+
player.addPotionEffect(new PotionEffect(Potion.digSlowdown.id, Config.sicknessTicks, 0, false, false));
130+
player.addPotionEffect(new PotionEffect(Potion.blindness.id, Config.sicknessTicks/4, 0, false, false));
131+
player.addPotionEffect(new PotionEffect(Potion.moveSlowdown.id, Config.sicknessTicks, 0, false, false));
73132
}
74133

75134
@SubscribeEvent
@@ -95,7 +154,7 @@ public void onPlayerDeath(LivingDeathEvent event)
95154
public void onUpdate(LivingUpdateEvent event)
96155
{
97156
if(event.entity instanceof EntityPlayer)
98-
{
157+
{
99158
EntityPlayer player = (EntityPlayer) event.entity;
100159
NBTTagCompound nbt = NBTHelper.getPersistedPlayerTag(player);
101160

@@ -105,6 +164,26 @@ public void onUpdate(LivingUpdateEvent event)
105164
{
106165
player.getFoodStats().setFoodLevel(20);
107166
}
167+
if(Config.ghostInvisibility == true)
168+
{
169+
player.addPotionEffect(new PotionEffect(Potion.invisibility.id, 50, 0, false, false));
170+
}
171+
}
172+
173+
if(Config.healthEffects)
174+
{
175+
if(player.getHealth() == player.getMaxHealth())
176+
{
177+
player.addPotionEffect(new PotionEffect(Potion.damageBoost.id, 5, 0, false, false));
178+
}
179+
if(player.getHealth() < player.getMaxHealth()/3)
180+
{
181+
player.addPotionEffect(new PotionEffect(Potion.moveSlowdown.id, 50, 0, false, false));
182+
}
183+
if(player.getHealth() < player.getMaxHealth()/2)
184+
{
185+
player.addPotionEffect(new PotionEffect(Potion.digSlowdown.id, 50, 0, false, false));
186+
}
108187
}
109188
}
110189
}
@@ -116,8 +195,9 @@ public void onItemPickup(EntityItemPickupEvent event)
116195
{
117196
EntityPlayer player = (EntityPlayer) event.entity;
118197
NBTTagCompound nbt = NBTHelper.getPersistedPlayerTag(player);
119-
120-
if(nbt.getBoolean("ghost") == true)
198+
199+
Item item = event.item.getEntityItem().getItem();
200+
if(nbt.getBoolean("ghost") == true && usableItems.contains(item) == false)
121201
{
122202
event.setCanceled(true);
123203
}
@@ -172,20 +252,6 @@ public void onPlayerAttack(LivingAttackEvent event)
172252
}
173253
}
174254

175-
private static List<Block> allowedBlocks = new ArrayList<Block>();
176-
177-
public static void loadAllowedBlocks()
178-
{
179-
allowedBlocks.add(Blocks.acacia_door);
180-
allowedBlocks.add(Blocks.oak_door);
181-
allowedBlocks.add(Blocks.birch_door);
182-
allowedBlocks.add(Blocks.spruce_door);
183-
allowedBlocks.add(Blocks.dark_oak_door);
184-
allowedBlocks.add(Blocks.lever);
185-
allowedBlocks.add(Blocks.wooden_button);
186-
allowedBlocks.add(Blocks.stone_button);
187-
}
188-
189255
@SubscribeEvent
190256
public void onPlayerInteract(PlayerInteractEvent event)
191257
{
@@ -195,21 +261,27 @@ public void onPlayerInteract(PlayerInteractEvent event)
195261
if(nbt.getBoolean("ghost") == true)
196262
{
197263
Block block = player.worldObj.getBlockState(event.pos).getBlock();
198-
if(allowedBlocks.contains(block))
264+
if(event.action == Action.RIGHT_CLICK_BLOCK && interactableBlocks.contains(block))
265+
{
266+
267+
}
268+
else if(event.action == Action.LEFT_CLICK_BLOCK && breakableBlocks.contains(block))
199269
{
200270

201271
}
202272
else
203273
{
204274
event.setCanceled(true);
205275
}
276+
206277
if(event.action != Action.LEFT_CLICK_BLOCK && player.getHeldItem() != null)
207278
{
208-
if(player.getHeldItem().getItem() == SHItems.heart_full)
279+
if(usableItems.contains(player.getHeldItem().getItem()))
209280
{
210281
event.setCanceled(false);
211282
}
212283
}
213284
}
214285
}
286+
215287
}

java/werty/softerhardcore/main/SofterHardcore.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ public class SofterHardcore
1616
public static SofterHardcore instance;
1717

1818
@SidedProxy(clientSide = References.CLIENT_PROXY_CLASS, serverSide = References.SERVER_PROXY_CLASS)
19-
public static CommonProxy proxy;
19+
public static CommonProxy proxy;
20+
21+
public static boolean hasCheckedVersion = false;
2022

2123
@EventHandler
2224
public void preInit(FMLPreInitializationEvent event)
@@ -31,7 +33,7 @@ public void init(FMLInitializationEvent event)
3133
{
3234
proxy.registerRenders();
3335
proxy.init(event);
34-
SHEventHandler.loadAllowedBlocks();
36+
SHEventHandler.loadAllowedBlocksandItems();
3537
}
3638

3739
@EventHandler
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
package werty.softerhardcore.main;
2+
3+
import java.io.BufferedReader;
4+
import java.io.IOException;
5+
import java.io.InputStreamReader;
6+
import java.net.URL;
7+
8+
import net.minecraft.util.ChatComponentText;
9+
10+
public class VersionChecker implements Runnable
11+
{
12+
private String versionToCheck;
13+
private String urlToCheck;
14+
private String name;
15+
16+
public static boolean hasChecked = false;
17+
18+
public static ChatComponentText uptoDate;
19+
20+
public VersionChecker(String versionToCheck, String url, String name)
21+
{
22+
this.versionToCheck = versionToCheck;
23+
this.urlToCheck = url;
24+
this.name = name;
25+
}
26+
27+
private boolean checkIfCurrent(String versiontocheck, String urlToCheck)
28+
{
29+
boolean upToDate = false;
30+
try
31+
{
32+
URL url = new URL(urlToCheck);
33+
BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
34+
String str;
35+
String version = "";
36+
37+
while ((str = in.readLine()) != null)
38+
{
39+
if (str.contains("version="))
40+
{
41+
version = str.substring(8);
42+
if (version.equals(versiontocheck))
43+
{
44+
upToDate = true;
45+
uptoDate = new ChatComponentText("§2"+ name + " is the current version");
46+
}
47+
else
48+
{
49+
upToDate = false;
50+
uptoDate = new ChatComponentText("§cA newer version of " + name +" is available: " + version);
51+
}
52+
}
53+
}
54+
in.close();
55+
}
56+
catch (IOException e)
57+
{
58+
System.err.println("Version file not found at: " + urlToCheck);
59+
uptoDate = new ChatComponentText("§c"+ name +" cannont find the latest version.");
60+
}
61+
return upToDate;
62+
}
63+
64+
@Override
65+
public void run()
66+
{
67+
checkIfCurrent(this.versionToCheck, this.urlToCheck);
68+
}
69+
}

0 commit comments

Comments
 (0)